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

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.

  1. The "PYTHON" touchpads are not supported in micro:bit mode.
  2. The buzzer uses the P0 port. To use the P0 touchpad, the buzzer must be turned off.

Was this article helpful?

TOP