Example Code for micro:bit-Motor Control Loop
Last revision 2025/12/30
This article provides detailed instructions on using micro:bit for motor control loops, including software setup, wiring diagrams, and sample code for continuous motor rotation.
Software Preparation
-
MakeCode Online Programming Platform:
https://makecode.microbit.org -
MakeCode Extension (Library) Repository:
Please copy the following library URL and paste it into the MakeCode Extensions search box:
https://github.com/DFRobot/pxt-DFRobot_creative-robotics-kit
Wiring Diagram
Insert the micro:bit with the LED matrix side facing the direction of the "micro:bit" logo, as shown in the diagram.

At this point, the expansion board supports the following features:
- All IO ports
- 2 motor drivers
- "0, 1, 2, 3V, GND" edge connector compatible with the micro:bit P0,P1,P2, 3V GND
- USB and PH2.0 external power, with power switch
- Buzzer and buzzer switch
Sample Code


Result
The result of the following program: Two motors rotate at speeds of 200 RPM and 100 RPM, rotating forward for 2 seconds, then backward for 2 seconds, and stopping for 2 seconds, continuously looping.
- The "PYTHON" touchpads are not supported in micro:bit mode.
- The buzzer uses the P0 port. To use the P0 touchpad, the buzzer must be turned off.
Was this article helpful?
