Example Code for micro:bit-Ultrasonic Obstacle-avoiding
- Learning Target: Keep the car away from obstacles - Effect: The ultrasonic sensor constantly detect the distance between the Maqueen and obstacle ahead, if it is smaller then 30cm, Maqueen randomly turns left or right to avoid the obstacle.
Hardware Preparation
- Maqueen Lite-micro:bit Educational Programming Robot Platform x 1 (ROB0148)
- micro:bit board x 1
- SR04 Ultrasonic Module x 1 or SR04-P Ultrasonic Module x 1
Software Preparation
- Makecode graphical online programming platform: makecode.microbit.org
- Maqueen library: Search for "dfrobot" in makecode extension and select "maqueen".
Wiring Diagram
Connect the ultrasonic module to Maqueen's ultrasonic interface (5V).
Other Preparation Work
Ensure the ultrasonic module is securely connected and free of obstructions.
Sample Code
Screenshot of Makecode Graphical Program:

Makecode Program Link: https://makecode.microbit.org/_V0yFaqJ4EEkD
Result

Additional Information
No additional content provided.
Was this article helpful?
