potentiometer lets you set the
sound volume that triggers the
sensor. Figure 2 shows the
Parallax sound impact sensor
which is both low cost and easy
to connect to the Arduino or
other microcontroller.

Though sound is analog, this
type of noise activation sensor
provides a digital off/on output
signal. The signal is normally off
(LOW) when the sound is below
the threshold level you’ve set
with the trimmer pot. Sound
above the threshold causes the
output to turn on (go HIGH).

Figure 3 shows how to wire
the sound impact sensor to
digital pin D2 on the Arduino.
This pin is specifically selected
because it is one of two Arduino
I/O pins that support external
interrupts; a change on this pin
can trigger a function in the sketch. By using an interrupt,
the Arduino doesn’t need to constantly poll the I/O pin to
determine the state of the sensor.

Polling requires the sketch to constantly monitor the
status of the input pin. If a sound event is very short and
occurs between polls, the Arduino may miss it. The more
tasks handled by the Arduino in its loop() function, the
more chance sound events will go unnoticed.

Interrupts are monitored in the background. The
interrupt is triggered only if and when a change occurs to
the input pin. As sound events can be fleeting, using an
interrupt to process them is the best method to ensure that
each one is captured.

Refer to Listing 1 for a demonstration of using the
Parallax sound impact sensor with an Arduino interrupt.
There are two important pieces that make the sketch work:
First is the attachInterrupt statement, found in the setup()
function. This statement sets up the interrupt, specifying
the interrupt number (interrupt 0 is on pin D2, interrupt 1 is
on pin D3); the name of the function that is executed when
an interrupt occurs; and the type of signal change that
causes the interrupt to trigger. The second important piece
is the interrupt function itself — called an interrupt handler
or interrupt service routine (ISR) in programming parlance.
In the sketch, the function is named sounder.

The Listing 1 sketch demonstrates how each event
that triggers the sound impact sensor toggles the Arduino’s
LED on or off. Set the trimmer pot on the sensor to adjust
its sensitivity. Turning it clockwise reduces sensitivity; turning
it counterclockwise increases sensitivity. Use the built-in LED
on the sensor to help you adjust the trigger level.

Here’s a tip: Collisions with objects cause noise. You

FIGURE 3.

Simple wiring
connection
between the
Sound Impact
Sensor and
the Arduino.

can use a sound impact sensor to detect if your ArdBot
has crashed into something. Increase sensitivity to hard
contact by mechanically fastening the sensor to the base
of the robot. Adjust the trimmer pot on the module to
capture the sound of running into an object. Avoid setting
the control so low that it will trigger on the robot’s
own motors.