Make an Automatic Sensor Door

by ElecFreaks in Teachers > 2

221 Views, 1 Favorites, 0 Comments

Make an Automatic Sensor Door

2022-2-10.jpg

Sonar:bit is a 3-wire ultrasonic module with the working voltage between 3-5V. It is available to be used to 3.3V or 5V micro-controller system. With only one 3-wire(GVS) cable, it can work properly. Compared to the normal 4-wire ultrasonic module, it has saved one IO port. The measurement range of sonar:bit is 4cm-400cm. It can output stable and accurate measurement data with ±1cm tolerance only.

Supplies

1.png
wukong-board.png
ef04089-1.jpg
ef10088-1.jpg
ef10155-1.jpg
2022-2-10-1 (1).jpg
2022-2-10-2 (1).jpg
2022-2-10-3 (1).jpg
2022-2-10-4 (1).jpg

House Drawings

2022-2-10-5.jpg

House Drawing File

Connection Steps Pictures

2022-2-10-7.jpg
2022-2-10-6.jpg
2022-2-10-8.jpg

1. 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

Hardware Connection:

2022-2-10-9.jpg

Hardware Connection:

Programming

2022-2-10-10.jpg
2022-2-10-11.jpg
2022-2-10-12.jpg
2022-2-10-13.jpg
2022-2-10-14.jpg

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.