18. IoT Case 09: Smart House door control¶
Use app inventor to create an APP to control the door of the house.
What is app inventor?
App Inventor allows user to develop their own app for Android phones or IOS device(iphone, ipad) by simple programming and design work.
Smart House door operation
When the micro:bit receives the signal “opendoor” from the app, the 180o servo will turn for 180o to open the door. When the micro:bit receives the signal “closedoor” from the app, the 180o servo will turn back 180o to close the door.
18.3. Part List¶
18.4. Assembly step¶
Attach the L-shaped stand with M3 screws and nuts to the model H1. Make a small hole to fix into the stand securely.
Attach the servo to the model H1.
Straighten the paper clip and cut it to 6.5 cm. Use pilers to fix the paper clip into the L-shaped stand.
Put together all the cardboard parts (H1-H2)
18.5. Hardware connect¶
Connect the 180ᵒ servo to P2 port of IoT:bit
|S (yellow)||S (orange)|
|V (red)||V (red)|
|G (black)||G (brown)|
18.6. Programming (MakeCode)¶
Step 1. Initialize OLED, IoT:bit and connect to WiFi
Initialize OLED with width:128, height: 64to
Initialize IoT:bit TX P16 RX P8from
Set Wi-Fi to ssid pwdfrom
Enter your Wi-Fi name and password. Here we set
Step 2. Set servo initial position
Turn Servo to … degreefrom
Turn servo to
180degree at pin
P2(the servo will control the door to be closed initially)
Step 3. Show icon “tick” after WiFi connection
On WiFi connectedand select icon
Device IDvariable from
On WiFi connectedto the
show stringblock placeholder
Step 4. Receive WAN command
Go to OLED
clear OLED displayto
On WiFi receivedto avoid overlap
On WiFi received
WAN_Commandvariable to show string placeholder
Step 5. Open/close door by WAN command
If Wan command
turn servo to 45 degree at P2(open door angle)
If Wan command
turn servo to 180 degree at P2(close door angle)
18.7. IoT (App Inventor)¶
* For more details, please refer to “Chapter 3: Direct control micro:bit by App Inventor 2”
Create the page with the components
Drag the components from the left menu – we will need buttons to open or close the door and a textbox for input the Device ID number.
Also, add the invisible component “Web” under connectivity, we will need it for WAN connection.
Make the programming part
The WAN control command URL is: http://control.smarthon.cc/publish?id=DeviceID&msg=ControlCommand
When Button1 is clicked, it will direct to the URL with given device ID and command “opendoor”.
When Button2 is clicked, it will direct to the URL with given device ID and command “closedoor”.
Download the App in your phone to by .apk or scan QR code.
Input your device ID number in the textbox, then click button “opendoor” to send command “opendoor”. Click button “Close Door” to send command “closedoor”.
With app inventor and micro:bit, you can control the door open/close by mobile app!
Q1. How can we add password authentication to open the door?
Q2. We can install the servo to different position in the house (tips: modify the turning angle of the servo)