distance measurement detectors used in robotics is the
ultrasonic transducer; see Figure 2 for how they work.
These sensors not only can detect if objects are nearby, but
with good accuracy, measure the distance between it and
that object. This lets you use an ultrasound sensor to not
only broadly determine if an object is nearby, but to check
by how much.
Using the Parallax PING)))
Ultrasonic distance measurement is pretty much an old
science. Polaroid used it for years as an automatic focusing
aid on their instant cameras. To measure distance, a short
burst of ultrasonic sound (usually at a frequency of around
40 kHz) is sent out through a transducer; in this case, the
transducer is a specially built ultrasonic speaker. The sound
bounces off an object and the echo is received by the same
or another transducer. A circuit then computes the time it
takes between the transmit pulse and the echo, and then
comes up with distance.
At sea level, sound travels at a speed of about 13,560
inches per second. This time
varies depending on atmospheric
conditions including air pressure
(which varies by altitude),
temperature, and humidity.
The time it takes for the echo
to be received is in microseconds
if the object is within a few
inches to a few feet of the robot.
The overall time between transmit
pulse and echo is divided by two
to compensate for the round-trip
travel time between the robot
and object. Given a travel time of
For the PropBot, I’ve selected the Parallax PING))) —
hereinafter referred to simply as Ping (to save on
parentheses characters). This sensor is one of the most
popular ultrasonic detectors used in hobby and amateur
robotics. It’s not the cheapest such sensor you can buy, but
it has great reliability. For sensors, it’s much better to spend
a few more dollars for dependability. The Ping is easy to
use, requiring just one signal line to the Propeller in
addition to power and ground.
Figure 3 is a basic wiring diagram for the Ping showing
the power, ground, and signal connection. Note the 1K Ω
resistor in-line between the Ping and the Propeller I/O pin.
Here’s why you need it: The Propeller is a 3.3V device; that is,
it’s powered by 3. 3 volts, and its input/output pins are
designed for 3.3V signals. The Ping is powered at five volts.
The good news is that the Propeller is designed to
tolerate five volt inputs, as long as the current from the
source is limited. So, even though the Ping is powered
by five volts and its signal line outputs 5V, the 1K
resistor safely limits the current reaching the Propeller.
You can use this same technique to interface most other
types of five volt sensors to your Propeller (but check the
datasheets just to be sure).
Figure 4 shows the hookup diagram between the
Ping and Propeller Activity board (PAB). To make the
wiring connection, I used a short three-wire servo
extension which has three-pin female connectors on
either end. On one end, simply slip the cable onto the
Ping’s power and signal pins. On the other, use a three-pin double-long male header. This header is like the
ordinary type of header with male pins, but on these the
pins on both sides are long. This allows the pins to both
plug into the female socket of the servo extension
connector and into the solderless breadboard.
Check out Listing 1: PropBot_PingTest for a
32 SERVO 12.2014
Figure 2. Ultrasonic
sensors work by emitting a
short burst of sound, then
measuring the length of
time it takes for the echo
to be received.
Figure 3. Basic wiring
diagram for the PING)))
sensor: signal, power
(five volts), and ground.