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.
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.
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 [2] about the speed of sound vs. air temperature to learn more about why this happens.
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.
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.
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 [3]. 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 [4]. Can you think of other ways sensors can be used to help?
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.
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?
Links
[1] https://www.parallax.com/product/28015
[2] https://learn.parallax.com/reference/speed-sound-air-vs-temperature
[3] https://www.youtube.com/watch?v=2IKT2akh0Ng
[4] http://www.cnn.com/2014/06/20/tech/innovation/sonar-sticks-use-ultrasound-blind/index.html