2.Security Door
Case Description
When someone is detected staying at the door for an extended period without entering the corresponding password, an alarm is triggered.
Key Knowledge Points
• Master the usage of the Sugar potentiometer module.
• Master how to use and retrieve data from the Cat Head Ultrasonic sensor.
Case Implementation
Structural Assembly
Circuit Connection
• Connect the Sugar potentiometer module to the Robotbit P1 terminal block.
• Connect the Cat Head Ultrasonic sensor to the Robotbit P2 terminal block.
• Connect the servo's 3-pin wire to the S1 port according to the corresponding colors.
Programming
We set the security door password to any digit from 1 to 9 (program defaults to 6). The potentiometer is used as the password dial input. The Micro:bit detects the potentiometer's analog value range of 0~1023, so a mapping block is required to convert the analog value range to 0~9.
!1631798062529-47a0daf7-1062-4452-a9ed-7f9c57ab7800.pngThe Cat Head Ultrasonic sensor is used, so the Robotbit expansion board must be initialized. The program starts with [Expansion Board Initialization].
When the door is locked, the servo angle is 0. When the correct password is entered (x=6), the servo angle changes to 90 degrees, and the security door can be opened.
Use ultrasonic distance detection to monitor prolonged presence. When the distance is less than 10 cm, a counter increments. If the counter exceeds 500, it indicates the person has stayed in front of the door for too long, triggering an alarm!
The program is as follows:
