of reference, the human voice spans a range of
about 150 Hz to 1,250 Hz; the 88 keys on a
piano range from 27 Hz to 4,187 Hz.

A sketch demonstrating how to use the
MSGEQ7 IC is provided in Listing 4. The code
displays (in the serial monitor window) the
relative values of the seven frequency bands,
from 0 to 1,023. Note that due to room and
electrical noise, the low end of the scale
commonly starts above 100. In operation, the
sketch cycles through the seven bands one at a
time, sampling the instantaneous voltage level
from pin 3 (DC output) of the MSGEQ7 IC. Once
all seven values have been collected, they’re
shown on the serial monitor window.

The EQ chip works best in quiet
environments without conflicting sound sources.
Ambient (natural) sounds — like the hum of a
computer fan or even the chirping of birds
outside — can influence the output. Even a
simple sound source — like one key on a piano —
produces many frequencies up and down the
audio spectrum. This is due to such things as
harmonics and sympathetic vibrations produced
by nearby objects. To make better sense of the
values returned by the MSGEQ7, you need to
weight all seven bands and use that data to
determine the center frequency of the sound
being analyzed.

One very simple method of weighting the seven
values is to determine which one is highest. Here’s a
function that finds the index with the highest value
(remember, Arduino array indices start at 0):

As frequency analysis is not 100 percent reliable,
use this method only for non-critical robot control
applications. With practice, you’ll get better at it.
Experiment with different kinds of frequency generators
to control your bot. With some patience, you might be
able to reliably reproduce a couple of distinct whistles.
Or, use a small plastic musical recorder as a kind of Pied
Piper controller for your bot. How about a harmonica or
Boatswain’s whistle? See what works best.