Example Code for micro:bit-MakeCode-Drive a motor
Drive a motor to rotate forward and backward.
Hardware Preparation
- micro:bit board: Quantity 1
- Micro: IoT expansion board: Quantity 1
- DC motor: Quantity 1
Software Preparation
- Makecode online graphical programming platform: https://makecode.microbit.org/
- Micro:IoT library: https://github.com/DFRobot/pxt-microIoT
- How to install an library?
Wiring Diagram
- Connect the DC motor to the motor ports of the Micro: IoT expansion board.
- Plug the micro:bit board into the Micro: IoT expansion board.
Sample Code
makecode programs: drive a motor
Result
the motor rotates forward at speed of 255 for 1 second, and then rotate backward for 1 second.
Was this article helpful?
