Example Code for micro:bit-Motion Sensor Switch
Last revision 2025/12/08
This guide explains how to set up a motion sensor switch using a micro:bit, including required hardware, wiring, and programming instructions with sample code.
Hardware Preparation
- Digital PIR (Motion) Sensor(SKU:SEN0171): 1
- 9g 180° Micro Servo (1.6kg)(SKU:SER0006): 1
- IO Expansion Board(SKU:MBT0014): 1
Software Preparation
Makecode online programming address: https://makecode.microbit.org.
Please copy the library link address and paste it into the Makecode extension to search: https://github.com/DFRobot/pxt-DFRobot_creative-robotics-kit
Wiring Diagram

Other Preparation Work
Copy the library link address https://github.com/DFRobot/pxt-DFRobot_creative-robotics-kit and paste it into the Makecode extension to search and add the library.
Sample Code

Result

Was this article helpful?
