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:
Moderate amount of corrugated paper
Appropriate amount of double-sided tape
house drawings
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
3. The ultrasonic is glued to the roof, and the light ring is glued to the door
Hardware Connection:
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.