Introduction: Make an Automatic Sensor Door

About: ElecFreaks is an open design house founded in March 2011. Our goal is to create rapid prototypes and give small-batch manufacture solution for makers and startups. With over 50% staff as engineers and expanded…

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

Step 1: House Drawings

House Drawing File

Step 2: 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

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

Step 3: Hardware Connection:

Hardware Connection:

Step 4: 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.

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.