Of these, the following four are used
FIGURE 5. MIDI pitches are defined using a
standard numbering system that corresponds
to the white and black keys on a keyboard.
• Program Change: Selects which
instrument to play.
• Note On: Turns on a note of a specific
pitch and velocity (more about these
• Note Off: Turns off the note.
• Control Change: Selects a variety of operations, such as
changing the volume of the channel or selecting a
different bank of instruments.
FIGURE 6. The Music(al) Instrument Shield from SparkFun
is a low cost MIDI sound module that plugs directly on top
of the Arduino.
Pressure 1010nnnn 0xA0
Control Change 1011nnnn 0xB0
Program Change 1100nnnn 0xC0
Channel Pressure 1101nnnn 0xD0
Pitch Bend Change 1110nnnn 0xE0
The nnnn bits specify the channel (0 to 15).
Each note you play on a MIDI device has two primary
characteristics: pitch and velocity. Pitch is the frequency of the note,
and velocity is its volume. On a piano, each white or black key
on the keyboard delivers a different pitch. How hard and quickly
you press down on the key determines its volume, or velocity.
MIDI uses a simple numbering system to denote pitch;
these numbers (see Figure 5) match the white and black
keys on a piano. Given a standard 88 key piano keyboard,
the MIDI pitch numbers vary from 21 (low tone) to 108 (high
tone). The sequential numbering counts both the white and
black keys. Very low and very high tones are possible by
extending the pitch values through the full 0-127 range. For
reference, middle C on the piano is MIDI pitch value 60. It has a
pitch (sound frequency) of 261.6 Hz (Hertz, cycles per second).
For note velocity, the values range from 0 (silent) to
127 (full volume). There is also a separate channel volume
command (see below) that sets the overall level for the
whole channel. Values likewise range from 0 to 127 for
overall volume. The example sketches in this article
demonstrate setting both note velocity and channel volume.
An example Note On message might look like this:
0x90|1 69 100
• 0x90 is the Note On command byte; 1 is added (ORed) to
it for channel 1.
• 69 is the pitch of the note. The value 69 represents the A
above middle C.
• 100 is the note velocity. A value of 100 is about
3/4 full volume (full = 127).
Note that I’m showing only the command byte
as hexadecimal; the rest are plain ol’ decimal.
The control change message allows for an
extended range of channel functions. These
messages use the 0xB0 command byte with a
channel number, a control byte, and a data byte to
FIGURE 7. Alternative MIDI sound modules include
these two board-level products, also from SparkFun:
a universal breakout board for use with a
microcontroller; and a combo MIDI/MP3 shield.
56 SERVO 04.2012