4. Case 01: Smart Saving Light Bulb¶
Level:
4.1. Goal¶
Make a smart light bulb by detecting motion around the environment.
4.2. Background¶
What is a Smart Light Bulb?
Smart light bulb is a smart light bulb that helps automation and saving electricity. When there is people coming in, the bulb will be turned on automatically. People always forget to turn off the light when he/she leave. After 10 mins, if there are no any motions inside the room, it will close the LED to save energy.
Smart Saving Light Bulb Principle
Motion sensor is used to detect the presence of human activity in the room. If there are people moving in the room, the light bulb will be turned on, vice versa.
4.3. Part List¶
4.4. Assembly step¶
Step 1
Step 1. To start with, build the Big House Model.
Step 2
Pick one corner of the house. In this example, we pick the left upper corner, install the 2 walls (E1 & E2) to build a small room.
Step 3
Attach the PIR Motion Sensor to model B3 using M4 * 10mm screws and nuts.
Step 4
Attach the Multi-color LED to the model B3 using M4 * 10mm screws and nuts.
Step 5
Installation completed!
Step 6
To build a Bed. Put model J2 onto the model J1, then put together all the cardboard parts (J1-J3).
Step 7
The bed completed!
Step 8
Place the bed inside the bedroom.
Step 9
Assembly completed!
4.5. Hardware connect¶
Connect the motion sensor to P0
Pull up the switch to avoid interference from buzzer
Connect the Multi-color LED(WS2812) to P1
4.6. Programming (MakeCode)¶
Step 1. Initialize Multi-Color LED
Before using the Multi-Color LED, need to do initialize
Pull the
set strip to NeoPixel at pin P1 with 1 leds as RGB(GRB format)
toon start
Step 2. Change the LED Color by motion sensor result
In
Forever
, add aif-else
statementSet (
Get motion (triggered or not) at Pin P0
=true
) as conditionSnap
strip show color white
into theif
segmentSnap
pause(ms) 10000
intoif
segment to keep light up for 10 secondSnap
strip show color black
into theelse
segmentWhen the condition is correct, that’s say motion is triggered, someone passes by.
The program will run theif
segment to turn on the lightOtherwise, the program will run the
else
segment to turn off the light
Full Solution
MakeCode: https://makecode.microbit.org/_MopaifFb42v5
You could also download the program from the following website:
4.7. Result¶
When the people are moving in the room, the motion sensor will trigger and keep the LED turned on. When there is no one moving, the LED will turn off.
4.8. Think¶
Q1. Besides implementing the smart light bulb into the toilet, where other places can the light bulb also be implemented? Discuss the place and briefly explain the point on energy reservation.
Q2. Suggest addition of any component that allows the light bulb to be even smarter.
Q3. Can you add the timer in the program to make it only turn off after 10min of no activity?