leads, or the servos may be
irreparably damaged. Figure 8
shows the main wiring diagram
for the Arduino, servos, servo
power, and switches.

Note the ground connection
between the servo battery
supply and the Arduino. This is
necessary for proper operation,
as it provides a common ground
between all subsystems.

Figure 9 shows how to
attach a pair of standard leaf
switches to the Musicbot. The
switches go on the front of the
robot (see Figure 10) and
provide an easy way to detect
collisions with objects on either
side of the bot. The levers on the
leaf switches can be extended by
using 1/4” (inside diameter)
rubber tubing — the kind used in
home aquariums. Cut the tube
to about 3”, and stuff over the
lever. Gently bend out the lever
so that the tube actuates the
switch when it’s pressed in.

Listing 2 demonstrates how
to control the Musicbot using
the two leaf switches as
bumpers. Whenever one of the
bumpers is activated, the robot
will briefly reverse then spin to
the right or left, depending on
which switch made contact.

Load up two short MP3 clips
onto your micro-SD card. Name
them track000.mp3 and
track001.mp3. The ideal length
of each clip is 1.5 to two
seconds. The length of the clip
is important because the
Musicbot will spin for as long
as the clip plays. Once the clip
is finished, the robot will go
forward again.

Extend the sound-playing
features of the Musicbot by
adding a self-contained infrared
receiver module. These work by
detecting the high frequency
pulses of an infrared remote
control, and decoding the signal
into a serial data train. Each
button on the remote provides a