make Tone is a user-defined function. It
sounds one or more tones through the piezo
speaker attached to pins 12 and 13. The code
is a bit elaborate, and more than can be
described here. For a detailed description, see
the Tone example provided on the
arduino.cc website.

The forward function is one of several motion control
routines that operate the two servos to move the robot.
Each servo is command to a specific position; either 0, 90,
or 180:

• 0 makes the servo turn continuously in one direction.

• 90 makes the servo stop.

• 180 makes the servo turn continuously in the other
direction.

This if test structure commands the Arduino to go
through a series of steps if the left bumper switch is
activated. The code first defines some musical notes to play
and sets the robot in reverse. After a short 1/2 second
delay — using delay(500) — the robot spins right, waits
another 1.5 seconds, then goes forward again.

void hitLeft() {
if (started)
pbLeft = HIGH;
}

A separate if test determines when the right bumper
switch is activated.

The hitLeft function is automatically called when the
left bumper is activated. The function sets the variable
pbLeft to HIGH. This variable is checked each time the
Arduino goes through the loop function. A separate
function hitRight is for the right bumper.

These lines of code check to see if there’s any recent
commands sent from the infrared remote control. If there
are, the sketch matches the command value received, then
operates the robot accordingly. For example, if the code is
hexadecimal 10 (shown as 0x10), then the robot turns left
while going forward. As a visual check, if the
robot is attached to your PC via the USB cable,
the code also displays a “1” — for button 1 —
in the Serial Monitor window. Buttons 2
through 9 are likewise matched; each button
makes the robot do something different.

In the next and final installment, we’ll look at some
alternatives to the Arduino Uno microcontroller board, as
well as explore using all-in-one shields that incorporate
servo headers and solderless breadboards — they make
wiring things up very easy. We’ll also discuss some other
low cost sensors you can connect to your ArdBot II to give
it a greater sense of the wide wide world around it. SV