LEGO Mindstorms

Touch Sensor

Programming Touch Sensors

What is the touch sensor?

The touch sensor is another type of sensor that can be used, which helps the robot navigate its surroundings and works by detecting if the sensor makes contact with something. For example, the touch sensor can be used to help determine where exactly an object is and where the robot is in the field. Using the touch sensor along with ultrasonic sensor can give a more precise reading in order to minimize error. 

 Touch sensors can be used in conditional blocks and loops, just like ultrasonic sensors, that can state if the touch sensor reads true, or is on, then go backwards for 1 second. If the touch sensor reads false, or is not active, then continue forwards for 3 seconds. These sensors can also be used in loops, but conditionals would be more effective because the touch sensor has 2 modes, 1 (pressed) or 0 (not pressed).

The conditional block above shows that if the touch sensor is pressed, go backwards for 1 second (as if you were backing up to not hit the same object again), and if the sensor has not been pushed, then go forward for 1 second.