16. IoT Case 07: Smart defense system¶
Make a smart defense system which emits sound and sends an email to the house owner if there are any suspicious movement near the door.
What is IFTTT?
IFTTT can help connect all your different apps and devices which enables them to work together to do specific tasks.
Smart defense system operation
The motion sensor can deliver a motion signal to the micro:bit. When the micro:bit detects the signal, the buzzer will emit sound and send an email to specific email account through IFTTT. Also, a monstor icon will be shown on the micro:bit if there are suspicious people passes by.
16.3. Part List¶
16.4. Assembly step¶
Attach the motion sensor to F1 model.
Put together all the cardboard parts (F1-F2)
16.5. Hardware connect¶
Connect the Motion Sensor to P1 port of IoT:bit
Turn on the Buzzer Switch on P0 port of IoT:bit
Pull the buzzer switch ’down’ to connect the buzzer in this execrise
16.6. IoT (IFTTT)¶
* For more details, please refer to Chapter 2: Send Email by IFTTT
Go to https://ifttt.com , create applet (if webhooks then Email)
Go to “My services” > “Webhooks”, select “Documentation” . Copy your Webhooks Key as follows:
16.7. 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: Show icon “tick” after WiFi connection
On WiFi connectedand select icon
Step 3. Check motion sensor value
if statementto block
WiFi is connected,
get motion (triggered or not) at Pin P1=
truethen, that’s say someone is near the door.
Step 4. Send notification when someone pass by
if statementto block
WiFi is connected, then snap
play tone Middle C for 1 beatfrom
basicand select a
Send IFTTT key…from
IoT Services, input your
IFTTT keyand input event name
Step 5. Show smile icon when no one pass by
Else, and select icon
if statementto the loop for 1 second delay for checking
When WiFi is connected, if there are any suspicious movement near the door, the buzzer will emit sound and an email will be sent to the house owner. Also, a monster icon will be shown on the micro:bit.
Q1. How to avoid sending duplicate emails? (tips: using variable)
Q2. How to distinguish suspicious people (e.g. password authentication)?