Goal


Materials


Background


What is a “smart telecontrol door opener”.

Principle of an analog noise sensor

Practical operation


The front side:

The back side:

Set and stick components as below:

Hardware Connect


Connect the analog noise sensor to the P1 port of the expansion board. Connect the crash sensor to the P2 port of the expansion board. Conenct the 180 deg servo to the P8 port of the expansion board. Connect the micro:bit to the batteries pack.

Software


makecode

Programming


Step 1

Note:If there is a hint says some codebase will be deleted because of incompatibility. Don’t worry. You could go ahead as the hint or build a new item in the item menu bar.

Step 2

Snap the on start block from the Basic, then snap the led enable block into the on start, set it to “false”. It is to close the LED display of the micro:bit. Click on the “Advanced”, choose the Pins and click the more. Snap the set pull pin block and set the P2 port to high level for providing an stable voltage. Initialize the OLED. Snap into the servo write block.Set P8 to 180, it is to set initial state of the servo to close the door. At last, set the variable to open and set its initialization value to flase for not open the door.

Step 3

Initialize the variable noise to save the received noise value. Under the forever loop, transmit the noise value of the P1 port to the noise varaible. If the noise value is greater than the 70db, it means someone is knocking the door and the OLED is showing “somebody out”. Snap the clear OLED display block and the show string block to display message.

Step 4

To judge the value of the crash sensor, using the digital read block to read the value of the crash sensor. That is the value of the P2 port. Set the value of the pin P2 to 0, and set the open variable to doors open. That is “set open to not false”. Set the varaible open to “true” and snap the servo write pin block, then set the value of the P8 port to 0. “pause(ms) 3000”, which means the opening time is 3 seconds.

Step 5

Else, set the servo write pin P8 to 180 and show string “nobody”, which means it is not need to open the door.

Program

Program link:https://makecode.microbit.org/_A10Fgf4hs36c

You also could directly download program by visiting website as below:


Result


Think


Questions


More Information