• In the “Wait” menu, find “Touch” and drag it into
step 2 (Figure 4).
• Make sure it’s configured to wait to be pressed, and
set to port 1 (Figure 5).
• Add a Move block that stops motors B and C
• Save your program, then download it to the NXT and
test it out.
Eddie should drive forward until he hits a wall, tripping
the touch sensor and stopping the motors to end the
program. With that program under our belt, let’s take this
It’s time to learn how to make Eddie avoid obstacles.
Start by opening your “Touch 1” program, and saving it as
“Touch 2” — that will preserve the Touch 1 program while
making a duplicate that we can modify.
• In the Touch 2 program, select the last step, where
we stopped motors B and C. Rather than stopping
when he hits a wall, we want Eddie to back up and
turn away. To do that, we’ll change this step to spin
the motors forward for two seconds, thus making the
robot move backwards. Confused yet? Check
Figure 7 to see what the code should look like
at this point.
• Now that Eddie will
back up, we need to
make him turn
briefly so he avoids
the obstacle. Add
another Move block,
and set motors B
and C to go forward
with the steering bar
SERVO 09.2010 45