Please find a printable version of this page HERE.
The touch sensor detects when the front part (red) of the sensor is pressed, for instance by slowly approaching an obstacle or by simply pressing it.
Attaching the Touch Sensor
Ask students to add the touch sensor to their robot. Learners can add the sensor themselves or follow pages 77-79 of their EV 3 Manual (Building Instructions).
Programming the Touch Sensor
The goal is to program the robot to change the display screen when the touch sensor is touched.
- This means that when the touch sensor is touched it will run one chain of commands.
- When the touch sensor is not touched it will run another chain of commands. This can be done using an <IF-THEN-ELSE> Block.
This practice task does not involve any robot movement, but it could be added on.
First, drag a Forever <Loop> Block from the orange Control menu onto the programming canvas. Without the Loop, the robot will only evaluate once and it will be hard to determine if the program works properly. Then, drag an <IF-THEN-ELSE> Block from the orange Control menu and make sure to put it “inside” the <Loop> Block.
Drag a <Touch Sensor> Block from the blue Sensor menu. Add it to the top of the <IF-THEN-ELSE> Block. It should fit perfectly.
Select the correct port: Check where you plugged the sensor into the base. The ports are labelled 1 – 4.
Now, add robot actions to determine what it will do when the sensor is pressed or not pressed.
Select a <Display> Block from the Displays menu and choose. We chose a “Big Smile” when the sensor is pressed, and a “Sad” expression when it is not pressed.
Optional: Add a <Stop> Block from the Controls menu to end your program. We added a <Stop> Block after the “Big Smile”. Once the sensor is pressed, the robot will display the smile and the program ends.
Find a printable version of this page HERE.
© 2022 Dr. Krista Francis & Stefan Rothschuh