Parallax PING))) ultrasonic sensor
excellent documentation, and has a nice feature set. It can detect objects in
a range between 2 centimeters and 3 meters, and we use it directly with a
breadboard, so we don t have to solder. It s also a perfect example of a sensor
that provides information via variable-width pulses. (More on that in a few
paragraphs.) With the PING))) sensor, we can easily build a sonar or a robot
that automatically finds its way through a maze without touching a wall.
As mentioned earlier, ultrasonic sensors usually
don t return the distance to the nearest object.
Instead, they return the time the sound needed
to travel to the object and back to the sensor.
The PING))) is no exception, and its innards are
fairly complex. Fortunately, they are hidden
behind three simple pins: power, ground, and
signal.
This makes it easy to connect the sensor to the
Arduino. First, connect Arduino s ground and
5V power supply to the corresponding PING)))
pins. Then connect the PING))) s sensor pin to
one of the Arduino s digital IO pins. (We re using
pin 7 for no particular reason.) For a diagram and for a photo of our circuit,
see
Figure 15, PING))) basic circuit, on page 80
basic circuit, on page
To bring the circuit to life, we need some code that communicates with the
PING))) sensor:
InputDevices/Ultrasonic/Simple/Simple.ino
const unsigned int
Line 1
const unsigned int
-
-
void
setup() {
-
Serial.begin(BAUD_RATE);
5
}
-
-
void
loop() {
-
pinMode(PING_SENSOR_IO_PIN, OUTPUT);
-
digitalWrite(PING_SENSOR_IO_PIN, LOW);
10
delayMicroseconds(2);
-
-
digitalWrite(PING_SENSOR_IO_PIN, HIGH);
-
delayMicroseconds(5);
-
1.
http://www.parallax.com/product/28015
Measuring Distances with an Ultrasonic Sensor
1
because it s easy to use, comes with
81.
PING_SENSOR_IO_PIN = 7;
BAUD_RATE = 9600;
www.it-ebooks.info
and
Figure 16, Photo of PING)))
79
report erratum
discuss
Need help?
Do you have a question about the Arduino Uno and is the answer not in the manual?