4. Case 01: Smart Saving Light Bulb

Level: level auto_fit

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.

pic_70

4.3. Part List


pic_90

4.4. Assembly step


Step 1

Step 1. To start with, build the Big House Model.

auto_fit

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.

auto_fit

Step 3

Attach the PIR Motion Sensor to model B3 using M4 * 10mm screws and nuts.

auto_fit

Step 4

Attach the Multi-color LED to the model B3 using M4 * 10mm screws and nuts.

auto_fit

Step 5

Installation completed!

auto_fit

Step 6

To build a Bed. Put model J2 onto the model J1, then put together all the cardboard parts (J1-J3).

auto_fit

Step 7

The bed completed!

auto_fit

Step 8

Place the bed inside the bedroom.

auto_fit

Step 9

Assembly completed!

auto_fit

4.5. Hardware connect


  1. Connect the motion sensor to P0

  2. Pull up the switch to avoid interference from buzzer

  3. Connect the Multi-color LED(WS2812) to P1


auto_fit

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) to on start

pic_90

Step 2. Change the LED Color by motion sensor result

  • In Forever, add a if-else statement

  • Set (Get motion (triggered or not) at Pin P0 = true) as condition

  • Snap strip show color white into the if segment

  • Snap pause(ms) 10000 into if segment to keep light up for 10 second

  • Snap strip show color black into the else segment

  • When the condition is correct, that’s say motion is triggered, someone passes by.
    The program will run the if segment to turn on the light

  • Otherwise, the program will run the else segment to turn off the light pic_90

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.

auto_fit

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?