Why Use Sensors?
1) Keep the Robot on Track
In Lesson 2 we saw that it can be difficult to get the robot to navigate around its environment by just telling it where it needs to go. Part of the problem is that small variations in its path can become really big errors once the robot has travelled a long distance. For example, if you are trying to get your robot to move straight ahead, and it is angled off path by just a little, it may only be a small amount off course after a few inches, but will be much further off course after it has travelled a few feet. You can see this in the picture below.

(Starting off course by a small amount can grow to a big error in a short while)
We can fix some of this inaccuracy by having the robot get information about its surroundings via sensors. This allows the robot to find out where it is by "seeing" what is around it, figure out if it is on the right path, and make corrections if needed.
2) Allow the Robot to interact with users and its environment
Sometimes you want the Robot to respond to a person or thing that it meets, or to give you information about the outside world. A robot will only know about its environment if it can sense it in some way. With the right sensors, a robot can tell if it has come across a dangerous object or what the conditions around it are like (for example how hot or cold it is).
For example, sensors allowed the Mars Rover, a robot that landed on the surface of Mars, to drive around the surface of the planet, without falling into a deep hole, or running into a big rock. Sensors also allowed the robot to detect and communicate the conditions on Mars back to scientists on Earth.
The Touch Sensor and Bumper
Today's lesson focuses on the touch sensor. It is a simple device that can detect whether someone or something touches, releases or "bumps" the orange button on its front. The button on the touch sensor is rather small, however, and it can be hard to press unless your robot is lined up perfectly with its target.
![]() (The Touch Sensor) |
![]() (The Touch Sensor with a Bumper) |
Programming with the Touch Sensor
The touch sensor can detect three different conditions. It can notice if it has been:
Pressed (the orange button has been pushed inwards)
Released (the orange has moved from being pushed in to its original position)
Bumped (the orange button was pushed and released in a short period of time)
There are two main ways to program with the touch sensor. The Touch Sensor block, checks in with the sensor, and waits to see if it has been triggered.
![]() (The Touch Sensor Block) |
![]() (Programming the Touch Sensor Block) |
The Wait for Touch Sensor will not do anything until the action specified (pressed, released or bumped) happens.
![]() (The Wait for Touch Sensor Block) |
![]() (Programming the Wait for Touch Sensor Block) |
Now that we know how it works, let's add a touch sensor to our Mindstorms Vehicle - 5 Minute Bot from the last lesson, and program it to perform some tasks…
Adding a Touch Sensor to "5-Minute Bot" to make "Bumper Bot"
We will start with the 5-minute Bot from last time. (The motor wires have been removed to make it easier to see)

Step 1: Attaching a Bumper Frame to the Touch Sensor



Step 2: Attaching the Bumper Arm to the Touch Sensor




Step 3: Attaching Rails to the 5-minute Bot



Step 4: Attaching the Bumper to the the 5-minute Bot



Step 5: Attaching the Wires (Connect the Touch Sensor to Port 1):

You're done building the Bumper Bot!
The Bumper Bot Programs
Exercise 1: Write a simple program to say "ouch" when the touch sensor is pressed and "hooray" when it is released. The pseudocode (program steps written in plain language) for this program looks like this:
Wait for touch sensor to get pressed.
Say "ouch".
Wait for touch sensor to get released.
Say "hooray".
Repeat from the beginning.
Step 1: We will want our program to repeat itself so that it can say "ouch"/"hooray" over and over again. Most of the time when you repeat actions inside a program it's a good idea to use a loop.
![]() (The Touch Sensor Block) |
![]() (Programming the Touch Sensor Block) |
Step 2: Wait for the touch sensor to get pressed.
![]() (The Touch Sensor Block) |
![]() (Programming the Touch Sensor Block) |
Step 3: Make an "ouch" sound.
![]() (The Touch Sensor Block + Sound Block) |
![]() (Programming the Sound Block) |
Step 4: Now wait for the touch sensor to get released.
![]() (The Touch Sensor Block + Sound Block + Touch Sensor Block) |
![]() (Programming the Touch Sensor Block) |
Step 5: Say "hooray", and the loop will return you to the beginning of the cycle.
![]() (The Touch Sensor Block + Sound Block + Touch Sensor Block + Sound Block) |
![]() (Programming the Sound Block) |
Exercise 2: Write your own program to have the "Bumper Bot" drive until the bumper hits something, then stop, back up about 6 inches, turn right and start over again. The pseudocode would look something like this:
Start driving forward.
Wait until the bumper is touched.
Stop.
Back up about 6 inches.
Turn right.
Repeat from the beginning
Challenges for You
(1) Just A Touch: See if you can get Bumper Bot to drive up to a block of Legos, and stop when it touches it without knocking the block over.
(2) Bump It Off: Use the touch sensor to get Bumper Bot to knock a block of Legos off the edge of a low platform (your instructors will set one up for you) without falling over the edge of the platform itself.
(3) Remembering The Distance: Have Bumper Bot travel to a wall, stop when it hits it and then travel backwards to the exact same starting place. You need to use the rotation sensor and data wires to do this.















