13. IoT Case 10: Smart Street Light¶
Level:

13.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.

13.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!

13.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
13.6. Programming (MakeCode)¶
Step 1. Initialize OLED, IoT:bit and connect to WiFi
Snap
Initialize OLED with width:128, height: 64toon startSnap
Initialize IoT:bit TX P16 RX P8fromIoT:bittoon startSnap
Set Wi-Fi to ssid pwdfromIoT:bitEnter your Wi-Fi name and password. Here we set
smarthonasSSIDand12345678aspassword
Step 2. Show icon “tick” after WiFi connection
Snap
show iconfrombasictoOn WiFi connectedand select icontickDraw the
Device IDvariable fromOn WiFi connectedto theshow stringblock placeholder
Step 3. Receive WAN command
Go to OLED
Snap the
clear OLED displaytoOn WiFi receivedto avoid overlapSnap the
show stringtoOn WiFi receivedDraw the
WAN_Commandvariable to show string placeholder
Step 4. Turn on/off LED by WAN command
Snap
if-conditionSet variable
WAN_Command=lightonintoif-conditionturn White LED …fromSmartCity>Output, turn white LED with intensity: 1023 at P0Set variable
WAN_Command=lightoffintoelse-if-conditionSnap
turn White LED …fromSmartCity>Output, turn white LED with intensity: 0 at P0
Full Solution MakeCode: https://makecode.microbit.org/S04795-22528-30275-73994

13.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

13.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.

13.9. Think¶
Q1. How to turn on the light automatically if the today’s weather is cloudy reported by IFTTT.
