Skip to content

Latest commit

 

History

History
90 lines (60 loc) · 2.63 KB

ultrasound-distance-sensor.md

File metadata and controls

90 lines (60 loc) · 2.63 KB
title layout meta-description share author about cats simple-description acknowledgements date date-updated
Ultrasound Sensor to Measure Distance
text-width-sidebar
Use ultrasound to measure distance to an object on the microbit
true
jez
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.
external
Ultrasound
Teaser image by Sparkfun (CC-BY). Sonar diagram by Georg Wiora CC-BY-SA-2.5
2016-12-23 10:20:00 UTC
2016-12-23 10:20:00 UTC

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

How Sonar Works

Example of Sonar{:.ui .image}

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.

{:.ui .dividing .header}

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{:.ui .image}

There are four pins:

  • VCC: for 3v voltage
  • Trig: triggers a pulse of ultrasound
  • Echo: outputs high if the pulse of ultrasound is detected.
  • GND: ground

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

{:.ui .dividing .header}

Electronics

Hook up the sensor as follows:

{:.ui .celled .striped .table}

HC-SR04 Sensor Microbit Pin
VCC 3v
GND GND
Trig PIN0
Echo PIN1

{:.ui .dividing .header}

Code

PXT.io

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.

{:.ui .dividing .header}

Notes

  • For use with Python, use an I2C ultrasound distance sensor. These are usually quite expensive.