$USD
  • EUR€
  • £GBP
  • $USD
PROJECTS micro:bit

micro:bit Project 6: Automatic Door

DFRobot Oct 15 2018 2449

Automatic doors can be found quite often in our daily life. When we are about to enter a convenient store, the door opens automatically and sometimes along with the sound “welcome~”.
In this lesson, we are going to learn how to build an automatic door using a motion sensor, which detects if someone comes over, and a servo to simulate the action of opening the door. Now, let’s begin!

Components needed
Main control board of micro:bit
Expansion board of micro:bit
1× button module
1× motion sensor
1× servo
1×  USB cable

Hardware Connection
Connect the servo to P0 
Connect the button module (motion sensor) to P1 


Program

Task1: Use the button module to control the servo
Goal: When the button is pressed, the servo rotates to 100°, and LED penal of the micro: bit shows “O”; When released, the servo stays at the 0°, and the and LED penal of the micro: bit shows “X”.

STEP1:The “servo write” function under “Pins” is used to control the servo. Since the servo is connected to P0, we will leave the “P0” as it is. The number“180” is the angle that we want the servo to reach. By changing this value we can set the servo to rotate between 0°~180°.


STEP2:Now, use the “if-else” function to determine the position of the servo based on the status of the button. When the button is pressed, the servo goes to 100°, otherwise it stays at 0°.Also, don’t forget to add the “O” and “X” to indicate the status of the button.


STEP3: By putting everything together, we will end up with a program shown as below. 


Need to notice that the servo has a relatively large power consumption, so we will need to use connect another power source through the extern USB power port.

Task2: Motion controlled door
Goal: we will replace the button with a motion sensor to control the servo. When someone approaches, the door opens. otherwise it stays closed.
STEP1: replace the button module with the motion sensor.


STEP2: The motion sensor is connected with the P1 pin of micro: bit, the value of motion sensor can be read by calling P1 pin. The procedure for calling instruction: pins (Advance) ---- digital read pin p0 . (After dragging the instruction, change P0 to P1)


STEP3:When a passerby is detected by the motion sensor, the servo rotates 100°and the micro: bit shows "O"l; otherwise the servo rotates 0°and the micro: bit shows "X". The instructions used are: if (true) - then – else.


STEP4: the final program.


REVIEW