In this lesson, you will learn how to display the values from an UltraSonic Sensor.
Step 1: Connect the HC-SR04 "GND" pin to a "GND" black pin on the Micro:Bit board.
Step 2: Connect the HC-SR04 "VCC" pin to a red pin on the Micro:Bit board.
Step 3: Connect the HC-SR04 "TRIG" pin to pin 14 on the Micro:Bit board.
Step 4: Connect the HC-SR04 "ECHO" pin to pin 15 on the Micro:Bit board.
Step 5: Open the MakeCode editor at https://makecode.microbit.org/.
Step 6: Create a new project by clicking on "New Project."
Step 7: Click "Extensions" and type "HC-SR04" add the below "Makerbit-ultrasonic" extension.
Step 8: Now, you can start programming the Micro:bit to use the HC-SR04 sensor. Here's an example code in MakeCode blocks:
Note: This code uses Micro:bit's P14 and P15 pins. Make sure the HC-SR04 sensor is correctly connected, with the Trig pin connected to the P14 pin and the Echo pin connected to the P15 pin.