What is the Touch Sensor and how to program it?

To access the full video please subscribe to FLLCasts.com
- #1626
- 04 Jun 2020
Touch Sensor
To put it simply, a touch sensor is an electrical switch similar to a light switch that closes an electrical circuit which has electrical current flowing through it.
Programming a Touch Sensor
In order to check if the sensor is pressed, we need to tell the program which port the sensor is connected to. This is done via the "TouchSensor()" and we enter the port inside the brackets.
The sensor ports are as follows:
- Port.S1 for port one;
- Port.S2 for port two;
- Port.S3 for port three;
- Port.S4 for port four;
After we enter the port where the sensor is connected, we can use the "pressed()" command to check if the sensor is pressed:
TouchSensor(Port.S2).pressed()
The "pressed()" command serves as the question "Is the button pressed?" and returns an answer of "True" or "False".
⚠️ The "pressed()" command does not initiate any sort of action in the robot. This command asks the sensor for its state a given moment and receives information about the state of the sensor.
Courses and lessons with this Tutorial
This Tutorial is used in the following courses and lessons

Python with LEGO Mindstorms EV3 - Level 2
In the second level of Python for EV3 robots, students learn in-depth the touch sensor. The sensor is used as an input device for manual control of machines, as well as a sensor for autonomous robots. In a pair of lessons, students build a control panel for the grabber and the movement of a crane. Programming wise, students learn how to fork code with "if-else" constructions, how to create conditional and forever loops with "while" and how to negate conditions with "not" operator. In the end of the lesson, robots can detect obstacles and avoid them, so that they traverse a simple labyrinth.
- 39
- 19:58
- 93

Lesson 1 - Security system.
Introduction
In this lesson, we will create a system that checks if the exit of a supermarket is closed or if there are still more people in the building. In big supermarkets, security guards must reassure that all of the clients have left the premises before they've locked the door.
However, there is always the odd case of someone getting locked in by accident, which is why there are security systems that notify the security guards they have made a mistake.
- 5
- 5
- 10
- 3d_rotation 1