Make-an-automatic-sensor-door.dwg
Connection steps pictures1. Download the drawing file and build the house with corrugated paper
2. Put Lego pieces on the 360° servo and stick to the door
3. The ultrasonic is glued to the roof, and the light ring is glued to the door
1. For programming, we need to add a package: click “Extensions” at the bottom of the MakeCode drawer and search with “wukong” in the dialogue box to download it.
2. Initialize the rainbow light first and set the pin to connect to P15
3. Set the ultrasonic pin to connect to P0, set the servo to 360° and connect to S0. If the ultrasonic detection distance is greater than 3cm and less than 15cm, the rainbow light will light up green, display yes and the servo rotates 160°, pause for 2000ms. If the ultrasonic detection distance is greater than 15cm, the rainbow light will turn off, display no and the servo rotates 240°, and pauses for 200ms.
4. Complete code link: https://makecode.microbit.org/_bt1WHWMr5ipj
The ultrasonic detection distance is reached. When there is an object approaching, the door will automatically open, and when there is no object, it will automatically close.
Comments
Please log in or sign up to comment.