Example Code for micro:bit-Drive the motor

Last revision 2025/12/30

This article explains how to use micro:bit to drive motors with example code, utilizing makecode graphical programming for continuous motor rotation forward and backward.

Software Preparation

Motor drive library address: https://github.com/DFRobot/pxt-micro-IOBOX
Programming Platform: makecode graphical programming

Sample Code

Drive the motor

Result

The effect of the program: Motor M1 and M2 rotate forward for 2 seconds at the speed of 150, then rotate reversely for 2 seconds with the same speed. Keep doing the actions repeatedly.

Was this article helpful?

TOP