FIGURE 11. Wiring diagram
between the Arduino and the
Parallax line follower module. The
servos are connected to Arduino
pins D6 and D7. See the
December ‘ 10 issue of SERVO for
details on how the ArdBot's
servos are connected.
instruments, playing a full octave’s
worth ( 12 steps) for each instrument.
You can use this program to
sample the various instruments to
discover how they sound.
Like the MIDI_Simple sketch,
the program in Listing 3 also uses
constants to define numeric values.
Only this time they’re placed in
separate header files to make it
easier to manage and update the
code. These header files are kept in the same folder as the
sketch, and are referenced at the top of the sketch using
Important! The Listing 3 sketch will not compile
without the extra header files. They’re included in the zip
file with all the sketches for this article at the download
link. Check the URL at the beginning of this article.
The multiple notes are played using this code:
noteOn(CHAN_1, m_note, m_velocity);
noteOn(CHAN_1, m_note+4, m_velocity);
noteOn(CHAN_1, m_note+7, m_velocity);
The m_note variable contains the root note to play The
additional two notes are defined as m_note+ 4 and
m_note+ 7; these numeric intervals create a major chord.
(Remember: The MIDI pitch values count half steps; that is,
both the white and the black keys.) The trio of notes are
contained in a for loop which cycles through a series of 12
half step notes.
For every note that’s turned on, you need to eventually
turn it off. This can be done by simply repeating the pitch
with a noteOff statement, or you can use a special “All
Notes Off” command to remove all notes playing on the
channel. The MIDI_Chords sketch in Listing 3 uses the
latter method to demonstrate how it’s done.
Tip: Play around with the delay after the notes are
turned on. Some instruments require a longer attack — the
amount of time for the note to come to full volume, timbre,
and form. If the delay is too short, the notes will literally
sound cut off.
ArdBot is a SparkFun MIDI shield (DEV-10587), an amplified
“capsule” speaker, and a Parallax eight-sensor line follower
module (#28034). The file follower module attaches to the
front of the ArdBot on one inch standoffs (included with
the module) and faces up, as shown in Figure 9. By using
your fingers or hand, you “play” tunes on the Tunebot to
control its behavior. Notes you play operate the servo
motors and make sounds through the MIDI board and
Note the resistor and capacitor interface between the
MIDI board and amplified speaker in Figure 8. This
interface is recommended by the manufacturer, and
prevents overloading the MIDI shield or amp. Specifically,
don’t hook up the GBUF pin (shown on the speaker
connections) as a ground; the GBUF pin is not at ground
FIGURE 12. Alternative Tunebot design, using a pair of
Tamiya three-speed gear motors and rubber tracks.
Building and Using the Tunebot
With the basics of MIDI out of the way, we can now
turn to the Tunebot (shown in Figure 1). I’m using an
ArdBot base which is detailed in SERVO November ‘ 10
through May ‘ 11. A kit of body parts is available at Budget
Robotics (see the Sources box for more info) or you can
cut out your own. The ArdBot is a low cost expandable
robot base that uses the Arduino Uno as its central brain.
Complementing the Arduino attached to the top of the
SERVO 04.2012 61