Datasheet

Tactile Navigation with Whiskers • Chapter 5
Robotics with the BOE Shield-Bot 151
How Whisker Switches Work
The whiskers are connected to ground (GND) because the plated holes at the outer edge of
the board are all connected to GND. The metal standoffs and screws provide the electrical
connection to each whisker.
Since each whisker is connected to digital I/O, the Arduino can be programmed to detect
which voltage is applied to each circuit, 5 V or 0 V. First, set each pin to input mode
with
pinMode(pin, mode), and then detect the pin’s state, HIGH or LOW, with the
function
digitalRead(pin).
Take a look at the figure below. On the left, the circuit applies 5 V when the whisker is not
pressed, so
digitalRead(7) returns 1 (HIGH). On the right, the circuit applies 0 V when the
whisker is pressed, so
digitalRead(7) returns 0 (LOW).
Most importantly, your sketch can store the return values in variables, such as
wLeft
and
wRight, and then use them to trigger actions or make decisions. The next example
sketch will demonstrate how.
Switch Lingo: Each whisker is both the mechanical extension and the ground electrical connection
of a normally open (off until pressed) momentary (on only while pressed) single-pole (one set of
electrical contact points), single-throw (only one position conducts) switch.
Testing the Whiskers
The next sketch tests the whiskers to make sure they are functioning properly, by displaying
the binary values returned by
digitalRead(7) and digitalRead(5). This way, you can
press each whisker against its 3-pin header on the breadboard, and see if the Arduino’s
digital pin is sensing the electrical contact.
Whisker Circuit
Applies 0 V
digitalRead(7)
returns 0
Whisker Circuit
Applies 5 V
digitalRead(7)
returns 1