Add obstacle detection to your buggy and robotics projects with this easy to use ultrasonic range sensor.
This is the HC-SR04 ultrasonic ranging sensor. This economical sensor provides 2cm to 400cm of non-contact measurement functionality with a ranging accuracy that can reach up to 3mm.
Each HC-SR04 module includes an ultrasonic transmitter, a receiver and a control circuit.
There are only four pins that you need to worry about on the HC-SR04: VCC, Trig, Echo and GND. VCC and GND are for power and Trig, Echo and GND are for your signal. GND is in with the signal set since it’s needed for a baseline.
You will find this sensor very easy to set up and use for your next range-finding project! The easiest pins to use on the microbit are 0, 1, and 2. So I used 0 for Trig and 1 for Echo.
This sensor works within the 3.3V – 5V range, if it is the only external device connected to the microbit then it can draw power from the microbit. If combined with other sensor it will need its own power supply.
Features:
- Operating Voltage: 3.3V – 5V DC.
- Operating Current: 15mA.
- Measure Angle: 15 degrees.
- Ranging Distance: 2cm – 4m.
Contents:
- 1 x HC-SR04 ultrasonic ranging sensor.
Dimensions:
- Length: 45mm.
- Width: 20mm.
- Max Height: 16mm.
- PCB Thickness: 1mm
- Pin Pitch: 2.54mm
Video:
Requires:
- A 3.3V – 5V power supply.
- A programmable microcontroller, such as; microbit, Arduino or Raspberry Pi.
Resources:
SparkFun Stock Code:
- SEN-13959.










Electron –
This is an excellent device for sensing walls and avoiding head on collisions. However be aware that the specification says its minimum supply voltage is 3.3V. A micro:bit supplied by a 3V battery has a nominal 3V pin voltage of about 2.8V and the distance sensor will not work. I have found that a micro:bit plugged into a Kitronik Motor Driver Board which has its own stabilized power supply providing 3.28V can operate this distance sensor but if you have any problems provide it with a 3.3V supply but do not exceed the micro:bit pin specification of Vdd +0.3V, The absolute maximum for the micro:bits power supply is Vdd 3.6V but stay well below this to avoid damaging your micro:bit.