Build and Test the Ping))) Sensor Circuit

In this activity, we will measure the distance to a variety of objects to get familiar with what the PING))) does, and does not, detect.  The PING))) sensor needs power, ground, and one signal connection for the Propeller to get distance measurements.

 

Parts List

  • (1) PING))) Ultrasonic Distance Sensor, as below (#28015)
  • (1) 2.2 k-ohm resistor (red-red-red)
  • (2) jumper wires

 

Build the PING))) Sensor Circuit

  • If you have not done so already, remove the touch-whisker circuits but leave the piezospeaker circuit in place.
  • Build the PING))) sensor circuit on your robot's Activity Board as shown below.
  • Make sure to use a 2.2 kΩ resistor between the PING))) sensor’s SIG pin and the Propeller I/O pin (P8 in this case).

    Wiring for the PING))) circuit and piezospeaker circuit. 

P14/P15 resistors are needed only for original ActivityBot kits using External Encoders (#32500).

PING))) Sensor and Servo Ports—Do not connect to VIN. If you want to connect the PING))) sensor to a servo port (such as P16 or P17) with a 3-pin extension cable, be sure to set the port's power jumper to 5V first, or you could damage your sensor.
Each servo port includes a 3.9 k-ohm resistor in series with its Propeller I/O pin, so you would not need to include the 2.2 k-ohm resistor shown in the schematic for the breadboard circuit.     

 

About the PING))) Sensor

The PING))) sensor emits a very high-pitched chirp and then listens for an echo, much like a bat.  By measuring the echo's return time, and using the speed of sound in the air, the Propeller microcontroller can determine the distance between the PING))) sensor and an object reflecting the chirp sound, up to 3.3 meters away.  This is how your ActivityBot can navigate using sound.

Echo based navigation only works with objects that can reflect the sensor's chirps effectively.  Small objects, or objects too far away, don't reflect enough sound.  Soft items, such as curtains and stuffed animals, may muffle the sound and not bounce back an echo.  Walls approached at a glancing angle will reflect the sound further away instead of back at the PING))) sensor. Hard-surfaced cylinders, ball-shaped obstacles, and walls faced directly reflect sound well. 

Air temperature can affect the accuracy of the PING))) sensor's distance measurements.  Check out our reference article about the speed of sound vs. air temperature to learn more about why this happens.

 

Test the PING))) Sensor

This program displays the PING))) distance measurements in the BlocklyProp Terminal.  You can use it to test how well the PING))) sensor can detect various objects and walls at various angles. This will give you an idea of what your ActivityBot can and cannot do with this sensor. 

Blockly Program for ActivityBot displaying distance with PING))) Sensor

  • Build the program shown above.
  • To set up the Ping distance block, first choose the unit, inches or cm (centimeters), for the value that the block provides.
  • Then, set the PIN to the Propeller I/O pin that is connected to the sensor.
  • Be sure to indicate your unit choice in the Terminal print text block.
  • Save your project.
  • Click the Run Once button, and, when the Terminal opens, you should see your text and a distance displayed.

  • Try measuring the distance to your hand, a cup, and a ball. All should be easy to detect.
  • Try measuring the distance to something soft, like a stuffed animal or a crumpled piece of fabric. Can the PING))) sensor detect an echo from it?
  • Try measuring a wall’s distance head-on.
  • Try measuring the distance to a wall, approaching at various angles.  How far from 90 degrees can the PING))) sensor still see the object?

 

How it Works

The PING))) sensor gets a brief high/low signal called a start pulse from the Propeller chip to start the measurement.  The sensor then makes its ultrasonic click and sets its SIG pin high. When the echo comes back, it sets its SIG pin low. The Propeller chip then can measure the duration of the PING))) sensor SIG pin's high signal, which corresponds to the echo return time. 

    

The Ping distance block takes care of the math for converting the echo return time measurement to distance.  In this program, the Ping distance block is plugged into a Terminal print number block, to display the measured value.  The Terminal print number block comes just after a Terminal print text block, to add a label and measurement units for the displayed value.  These two blocks are in a repeat forever block, along with a pause (ms) and Terminal clear screen block. The pause (ms) block slows down the repeat loop enough to get a smooth display, and the Terminal clear screen block keeps the value updated. 

 


Did You Know?

Sound is measured in hertz (Hz). The PING))) sensor emits chirps at 40 kHz, well above human hearing. Most young humans can hear frequencies between 20 Hz and 20 kHz, while some bats can hear frequencies up to 100 kHz. So, while you cannot audibly hear the PING))) sensor's chirps, a bat most likely could.

Even though the PING))) sensor uses a sound that is a higher frequency than a human can hear, lower frequency sounds can bounce off of objects, too.  Watch this video about an incredible person who is blind, but can "see" using echolocation: BBC Earth: Blind man uses echolocation like a dolphin.  Although he was able to develop that sense himself, sensors like the PING))) can be used to help others with disabilities.  Read this article showing a product that could help others: CNN: sonar sticks.  Can you think of other ways sensors can be used to help?


Try This

Since there is a piezospeaker on the board, let's use tones instead of the Terminal to express the distance measured by the PING))) sensor.  The next program saves the block's value in a variable and then uses math to scale the measured distance to a frequency range played on the piezospeaker.

  •  Create a new project and name it something like PingPiezo.
  • Build the project shown below.

  • Use the Load and Run (Save to EEPROM) button to program the ActivityBot.
  • Disconnect the ActivityBot from the computer and point it toward a wall straight on, about 10 feet away. Then walk towards the wall. Can you hear the beep get higher pitched the closer you get to the wall?

 

Your Turn

Take a closer look at the project above. Can you see how the Distance variable controls the Hz variable, with the help of two operators and two constants?

  • What is the highest frequency the piezospeaker will play using this code? What is the lowest?
  • Make a copy of the project that uses inches instead of centimeters to take the Ping))) distance measurement, but still plays frequencies across a similar range.