19. IoT Case 10: Smart Street Light¶
Level:
19.2. Background¶
What is Smart Street Light?
To improve the living stand of citizen and to save electricity, smart street light can be automatically turned on at night (eg.6pm) and turned off in the morning (eg.6am)
Smart Streetlight operation
When WAN commands are received from WAN (eg. IFTTT), micro:bit will get the command name. If the command name is “light_on”, the LED light will be turned on. If the command name is “light_off”, the LED light will be turned off.
19.4. Assembly step¶
Step 1
Attach the LED light to the model I2 with M4 screw and nuts. Put together all the cardboard parts (I1-I3)
Step 2
Assembly completed!
19.5. Hardware connect¶
Connect the white LED Light to P0 port of IoT:bit
Pull the buzzer switch ‘up’ to disconnect the buzzer in this execrise
19.6. Programming (MakeCode)¶
Step 1. Initialize OLED, IoT:bit and connect to WiFi
Snap
Initialize OLED with width:128, height: 64
toon start
Snap
Initialize IoT:bit TX P16 RX P8
fromIoT:bit
toon start
Snap
Set Wi-Fi to ssid pwd
fromIoT:bit
Enter your Wi-Fi name and password. Here we set
smarthon
asSSID
and12345678
aspassword
Step 2. Show icon “tick” after WiFi connection
Snap
show icon
frombasic
toOn WiFi connected
and select icontick
Draw the
Device ID
variable fromOn WiFi connected
to theshow string
block placeholder
Step 3. Receive WAN command
Go to OLED
Snap the
clear OLED display
toOn WiFi received
to avoid overlapSnap the
show string
toOn WiFi received
Draw the
WAN_Command
variable to show string placeholder
Step 4. Turn on/off LED by WAN command
Snap
if-condition
Set variable
WAN_Command
=lighton
intoif-condition
turn White LED …
fromSmartCity
>Output
, turn white LED with intensity: 1023 at P0Set variable
WAN_Command
=lightoff
intoelse-if-condition
Snap
turn White LED …
fromSmartCity
>Output
, turn white LED with intensity: 0 at P0
Full Solution MakeCode: https://makecode.microbit.org/_6DuRvwD5PYpU
19.7. IoT (IFTTT)¶
* For the setting of IFTTT, please refer to “Chapter 4: Cloud Control micro:bit by IFTTT”
Step 1. Create applet in IFTTT
19.8. Result¶
The micro:bit is controlled by IFTTT (trigger by date&time). The LED light will be turned on at 6pm and turned off at 6am every day.
19.9. Think¶
Q1. How to turn on the light automatically if the today’s weather is cloudy reported by IFTTT.