Purpose of this tutorial:
In this tutorial we will learn how to use a reference ultrasonic distance sensor HC-SR04 with Micro:bit.
- Micro:bit card
- ultrasonic sensor HC-SR04
- Micro:bit GPIO Expansion Board (for mounting 1)
- connecting wires
The assembly is disconcertingly simple:
- The 3.3V power supply from the Micro:bit card goes to the VCC pin of the sensor.
- The GND pin of the Micro:bit card goes to the GND pin of the sensor.
- The P1 pin of the micro: bit card goes to the TRIGGER pin of the sensor.
- The P0 pin of the micro: bit card goes to the ECHO pin of the sensor.
There are several mounting methods.
Here is the makecode program which displays the distance in cm on the micro: bit card which separates the ultrasonic sensor from an obstacle. Note: You must go to Extensions to import the Sonar extension.