10. Case 01: Automated Smart Playground Lamp¶
Make a smart playground lamp by detecting the motion nearby.
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.3. Part List¶
10.4. Assembly step¶
Attach motion sensor and white LED to A1 model with M4 * 10mm screws and nuts.
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.
led enable falseto
Note that P3 is used as LED in default setting, LED need to be disable
Step 2. Turn on LED by motion sensor
get motion (triggered or not) at P0 = true, into
if statementthat’s say motion is triggered, someone passes by.
turn white LED to 1023 at P3as turning on white LED and pause 10 seconds.
turn white LED at P3 to 0as turning off.
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.
Q1. How can you use motion sensors, other than turning on the light automatically?
Q2. Can you show motion sensor value on OLED?