Example Code for micro:bit-Servo

Last revision 2025/12/31

This article offers a detailed guide on integrating a servo motor with the micro:bit using Makecode and Mind+. It covers hardware and software preparation, wiring setup, and provides a sample code to execute the servo's rotation when a key is touched.

Hardware Preparation

  • Math & Automatic expansion board for micro:bit, Quantity: 1
  • micro:bit, Quantity: 1
  • Servo, Quantity: 1

Software Preparation

Makecode graphical programming, Mind+ platform.
Makecode Library Address.
About how to install a software library?

Wiring Diagram

No specific wiring required (touch keys are integrated on the board).

Other Preparation Work

Install the Makecode library from https://github.com/DFRobot/pxt-Math-Automatic.
About how to install a software library?

Sample Code

Servo

Result

When key 5 is touched, servo S1 rotates 180 degrees and backs to 0 degree 1 second later.

Was this article helpful?

TOP