Example Code for micro:bit-Obstacle Avoidance
Last revision 2026/01/14
The article offers example code for micro:bit obstacle avoidance featuring Maqueen Plus V2 and ultrasonic sensors, with detailed wiring instructions and programming tips for basic and improved car turning reactions upon detecting obstacles.
Hardware Preparation
- Maqueen Plus V2
- micro:bit V1/V2
- Ultrasonic Sensor (included)
Software Preparation
Wiring Diagram
Ultrasonic Sensor is plugged in as per Quick Start Guide.


Other Preparation Work
- Complete the Quick Start Guide steps.
- Ensure the ultrasonic sensor is properly connected.
Sample Code
Basic Program Link: https://makecode.microbit.org/_DKCHUJgTgJFo

Improved Program Link: https://makecode.microbit.org/_RYRVeb318fVt

Result
Basic: Car turns in one direction when obstacle is within 30cm.
Improved: Car randomly turns left or right when obstacle is detected.
Was this article helpful?
