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

Wiring Diagram

  1. Connect the soil moisture sensor to P1 of the Micro: IoT expansion board.
  2. Connect the servo to S1 of the Micro: IoT expansion board.
  3. Plug the micro:bit board into the Micro: IoT expansion board.

Other Preparation Work

  1. Open the Easy IoT website:http://iot.dfrobot.com.cn/
  2. Sign up/Sign in to Easy IoT.
  3. 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?

TOP