SERVO 04.2016 31
Post comments on this section and find any associated files and/or downloads at
(past the contact point, of course) with a straw, wood, or
some other material. You can connect a whisker in the
same manner you would connect a bumper switch (shown
later) because a whisker is basically a simple normally open
switch. You can find a nice explanation of how to build
your own whiskers at http://education-archive.
These days, I mostly use IR and ultrasonic sensors
instead of bumper sensors (and whiskers). However, there
are cases where some form of a bumper switch is
appropriate. Lately, I have been using limit switches with a
large paddle lever like the one shown in the photo.
To avoid cuts on little fingers, I cover the end with
something handy, such as bumpers made of wood or
plastic, small rubber caps, or plastic drinking straws. You
can let your imagination run wild!
“GPIO PIN” is any of the available GPIO pins on your
Pi’s GPIO header that does not have a voltage divider
connected to it, or any available I/O pin on an I/O
expander such as the MCP23S17 used on my
To read a bumper switch, just set the pin it’s
connected with to INPUT with the appropriate call for the
library you are using (such as pinMode(pin, INPUT)), and
read it with digitalRead(pin).
IR Bumpers and Line
Analog short range IR distance sensors, IR line sensors,
and IR bumpers all work the same way. An infrared LED is
illuminated, and the amount of light that is returned is
measured by a phototransistor. Depending on the strength
of the illumination, the sensitivity of the phototransistor,
and the amount of reflected light, the phototransistor will
conduct more or less current, which can be read as a
voltage using a pull-up resistor.
If the object is too far away to be read or there is
black tape that does not reflect much light, you will get a
different reading than from a lot of reflected light from a
nearby object (such as white paper).
SirMorph — my IR bumper sensor — can also be used
as a line sensor and (very) short range distance sensor,
with a working distance of up to 20 mm with the default
There are also digital line sensors, which usually use a
potentiometer to set an output level for 0 or 1 based on
the amount of reflected light. I strongly prefer the analog
sensors, as digital sensors are a lot less flexible.
To these sensors, you simply use the analogRead(pin)
function of wiringPi or a similar library.
Limit switch used as a bumper.
Connecting such a switch
to a 5V digital input is
SirMorph IR sensor.