Ultrasound

Sonar uses sound to detect objects. It can be used to measure distance to an object.

How Sonar Works

Example of Sonar

The distance from the sensor to the object can be calculated by measuring the time sound takes to return to the sensor after a pulse.

Component

A HC-SR04-compatible sensor module has a speaker and microphone; one sends an ultrasonic pulse of sound, the other receives it. By measuring the difference between the pulse and echo, the distance to the object can be calculated.

HC-SR04

There are four pins:

Searching Amazon or eBay for HC-SR04 will reveal many examples of these sensors. They’re around £1 each.

Electronics

Hook up the sensor as follows:

HC-SR04 SensorMicrobit Pin
VCC3v
GNDGND
TrigPIN0
EchoPIN1

Code

The ultrasound sensor requires measurements in microseconds and so is only available in PXT.IO. You will need to add the sonar package to the project.

Notes

Share On
Facebook Twitter Google Plus

Published: December 23, 2016 Updated: December 23, 2016

Acknowledgements: Teaser image by Sparkfun (CC-BY). Sonar diagram by Georg Wiora CC-BY-SA-2.5

Ultrasound

Sensor sends an ultrasound pulse and listens for the echo. It returns the distance to a target by how long the echo took to return.

Jez Dean
Teacher