How to Make An Automatic Door for your Automation Home

For this practice we are going to build a cardboard house with a door that opens automatically due to proximity.

When there is an object approaching, the door will open automatically and when there is no object it will close automatically.

 

Necessary Materials

ELECFREAKS BBC micro:bit V2.2
Wukong Expansion Board Adapter
Sonar:bit
ELECFREAKS 8 RGB Rainbow LED Ring 
360° Servo
2 x Dupont Cables
Building blocks
Cardboard and double-sided tape

micro bit

Note: Sonar:bit is the ultrasound module. The measurement range of the sonar:bit is 4cm-400cm. It can output stable and accurate measurement data with a tolerance of ±1cm only.

 

Step by Step Assembly

1. Download the  cut-out house drawing and build the house with cardboard

micro bit

2. Place the LEGO® or compatible pieces on the 360º servo and stick them to the door

micro bit

3. The ultrasonic sensor is placed on the ceiling and the LED indicator near the door

 

micro bit

 

Hardware connection

micro bit

 

1. To program it we need to add an extension. Click "Extensions" and search for "wukong" to download it.

micro bit

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

micro bit

3. Set the ultrasonic pin to connect to P0, set the servo to 360° and connect it to S0.

If the ultrasonic detection distance is greater than 3cm and less than 15cm, the rainbow light will turn green, "yes" will be displayed and the servo will rotate 160°, pausing for 2000ms.If the ultrasonic detection distance is greater than 15cm, the rainbow light will go out, display no, the servo will rotate 240° and pause for 200ms.

micro bit

4. You have the complete code solved at https://makecode.microbit.org/_bt1WHWMr5ipj