FIGURE 3. A pair of leaf switches on the
ArdBot. You can attach things to the leaf of each
switch to enlarge its contact area.
Solder the end(s) to the leaf. Or, you can use
thin pieces of wood, plastic, or metal. Just be
sure the weight of the extension doesn’t
accidentally activate the switch. You don’t
want false alarms.
The switch may be directly connected to
a motor or, more commonly, it may be
connected to a microcontroller. A typical
wiring diagram for the switch is shown in
Figure 2. The 10 kΩ pull-down resistor is
there to provide a consistent digital LOW (0 volts) output
for the switch when there is no contact. When contact is
made, the switch closes, and the output of the switch goes
HIGH — usually five volts, as shown here.
Using Leaf Switches
Two standard leaf switches mounted to the front of
your ArdBot let it detect when it’s hit something. With
the switches situated to the sides, your bot can determine
if the object is on the left or on the right, and then steer
Figure 3 shows a pair of leaf switches mounted like
bumpers to the front of the ArdBot. Switches like these
are available at many online electronics outlets, and are
common as surplus. I bought these at All Electronics
(a SERVO Magazine advertiser) for $1.60 a pop.
I haven’t augmented the switches with a larger contact
area, as I’m more interested in demonstrating the concepts
involved. Use your creativity in enhancing the switches to
provide the level of sense detection you want. For example,
right off you can see that the robot is “blind” to small
objects directly between the switches. You can deal with
this either by enlarging the contact area, or (my choice)
using another form of “sense” to avoid collision in the
To mount each switch, find two suitable holes in the
base of your robot, or drill new ones. Most leaf switches
have three connections: common, normally open (NO), and
normally closed (NC). Wire the common and NO
connections. If space is tight, break off the NC connection
to make room.
Figure 4 shows the diagram for connecting the two
switches to digital pins D2 and D3 of the Arduino. Figure 5
shows the same circuit, but in breadboard view. Use the
upper half of the ArdBot’s 170 tie point solderless
breadboard. The bottom half is already in use by the servo
wiring for the ArdBot (see Part 2 of this series).
On my prototype, I made connectors for the switches
by soldering the two wires to pins of a breakaway male
header. With these, you break off the number of pins you
FIGURE 4. Schematic view of connecting two bumper switches
to the Arduino microcontroller.
FIGURE 5. Breadboard view of connecting the bumper
switches. Note that the bottom half of the solderless
breadboard is already in use, wired for the two servo motors.
(See Part 2 of this series for details.)
SERVO 02.2011 69