Make an automatic sensor door

Make an automatic sensor door

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.

Materials required:

Make an automatic sensor door
BBC micro:bit V2 x 1

Make an automatic sensor door
Wukong expansion board x 1

Make an automatic sensor door
Sonar:bit x 1

Make an automatic sensor door
8 RGB Rainbow LED Ring x 1

Make an automatic sensor door
360°servo x 1

Make an automatic sensor door
Dupont cables x 2

Make an automatic sensor door
Building Blocks x N

Make an automatic sensor door
Moderate amount of corrugated paper

Make an automatic sensor door
Appropriate amount of double-sided tape

house drawings

Make an automatic sensor door

house drawing file

Make-an-automatic-sensor-door.dwg

Connection steps pictures

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

Make an automatic sensor door

Make an automatic sensor door

3. The ultrasonic is glued to the roof, and the light ring is glued to the door

Make an automatic sensor door

Hardware Connection:

Make an automatic sensor door

Programming

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.

Make an automatic sensor door

Make an automatic sensor door

2. Initialize the rainbow light first and set the pin to connect to P15

Make an automatic sensor door

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.

Make an automatic sensor door

4. Complete code link: https://makecode.microbit.org/_bt1WHWMr5ipj

Make an automatic sensor door

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.