10. Case 01: Automated Smart Playground Lamp¶
Level:
10.1. Goal¶
Make a smart playground lamp by detecting the motion nearby.
10.2. Background¶
What is smart playground lamp?
Smart playground lamp is a lamp which can open automatically when someone passes by. Installing an auto-light can help the earth save electricity. When no one passes by, the light will automatically turn off.
Smart playground lamp operation
Motion sensor should be able to detect if there are people moving in the playground.
If there are people moving in the playground, the LED light should turn on, vice versa.
10.4. Assembly step¶
Step 1
Attach motion sensor and white LED to A1 model with M4 * 10mm screws and nuts.
Step 2
Assembly completed!
10.5. Hardware connect¶
Connect Motion sensor to the P0 port of Smarthon IoT:bit
Connect LED light to the P3 port of Smarthon IoT:bit
Pull the buzzer switch ‘up’ to disconnect the buzzer in this execrise
10.6. Programming (MakeCode)¶
Step 1. Disable micro:bit LED.
Snap
led enable false
toon start
Note that P3 is used as LED in default setting, LED need to be disable
Step 2. Turn on LED by motion sensor
Drag
forever
fromBasic
Snap
if statement
intoforever
Set
get motion (triggered or not) at P0 = true
, intoif statement
that’s say motion is triggered, someone passes by.Then,
turn white LED to 1023 at P3
as turning on white LED and pause 10 seconds.Else,
turn white LED at P3 to 0
as turning off.
Full Solution
10.7. Result¶
Motion sensor is used to detect if there are people moving in the playground. If there are, the LED light will be turned on; otherwise, it will be turned off.
10.8. Think¶
Q1. How can you use motion sensors, other than turning on the light automatically?
Q2. Can you show motion sensor value on OLED?