+21622886281
HC-SR04 Micro:bit

Measure the distance between an obstacle and the HC-SR04 sensor with Micro:bit

Purpose of this tutorial:

In this tutorial we will learn how to use a reference ultrasonic distance sensor HC-SR04 with Micro:bit.

Components required

  • Micro:bit card
  • ultrasonic sensor HC-SR04
  • Micro:bit GPIO Expansion Board (for mounting 1)
  • connecting wires

Mounting

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.

Montage (1)

Montage (2)

Makecode program

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.




0 commentaire


Leave a comment

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *

Scroll to Top