Echolocation / Sonar Navigation
This demo is designed to introduce an example of selecting a a sensor, identifying its properties, finding sample code, implementing code and testing, modifying code, and actuating lights and sounds as an output. Let’s get started.
Process:
- Obtain a sensor, for example the HY-SRF04 or 05 ultrasonic rangefinder ($6). Other great sources are Adafruit.com, Sparkfun.com.
- Search for information on using it. Adafruit is best for teaching and providing tutorials and code. Since the rangefinder is from Amazon, we need to Google it.
- Find a datasheet and sample code. Copy and paste code to a new Codebender script. The code describes the pin connections, here it needs (1) +5V power, (2) ground, (3) “trigger” digital input, and (4) “echo” digital output.
- Wire up the circuit.
- Verify the code and install it on your Arduino. The code triggers the ultrasonic sensor to emit 8 pulses, receive an echo, and output a pulse to the echo pin with a duration equal to the echo delay. A variable reads this time delay in microseconds. Using the speed of sound in air (343.2 m/s at 20C) and echo appearing at twice the distance (there and back), the distance in cm is given by L(cm) = t(us) * 0.03432 cm/us / 2. The distance is written out to the serial port.
- Select Serial Monitor on Codebender and Start at the bottom. Ultrasonic range distance data should appear about once per second.
2015 DRA, licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.