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

Wiring Diagram

  1. Connect the DC motor to the motor ports of the Micro: IoT expansion board.
  2. 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?

TOP