Example Code for micro:bit-MakeCode-Automatic Clothes Hanger
Explore the step-by-step guide to building and programming an automatic clothes hanger using micro:bit, servo, and soil moisture sensor, with instructions for controlling it via Easy IoT or manually.
Hardware Preparation
- micro:bit board: Quantity 1
- Micro: IoT expansion board: Quantity 1
- Soil moisture sensor (P1): Quantity 1
- Servo (S1): Quantity 1
- DFRobot Easy IoT platform access: 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 soil moisture sensor to P1 of the Micro: IoT expansion board.
- Connect the servo to S1 of the Micro: IoT expansion board.
- Plug the micro:bit board into the Micro: IoT expansion board.
Other Preparation Work
- Open the Easy IoT website:http://iot.dfrobot.com.cn/
- Sign up/Sign in to Easy IoT.
- Add a new device to match your micro:bit, get the device topic.
Sample Code
Makecode Programs: automatic clothes hanger
Result
When Easy IoT sends "ON", the servo rotates to 160 degrees to stretch the clothes hanger; when Easy IoT sends "OFF", the servo rotates to 30 degrees to retract the clothes hanger. Or we can control it manually by pressing the button A and B.
Was this article helpful?
