10. Case 01: Automated Smart Playground Lamp

Level: level auto_fit

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.

pic_60

10.3. Part List


auto_fit

10.4. Assembly step


Step 1

Attach motion sensor and white LED to A1 model with M4 * 10mm screws and nuts.

auto_fit

Step 2

Assembly completed!

pic_40

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


auto_fit

10.6. Programming (MakeCode)


Step 1. Disable micro:bit LED.

  • Snap led enable false to on start

  • Note that P3 is used as LED in default setting, LED need to be disable auto_fit

Step 2. Turn on LED by motion sensor

  • Drag forever from Basic

  • Snap if statement into forever

  • Set get motion (triggered or not) at P0 = true, into if 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. pic_90

Full Solution

MakeCode: https://makecode.microbit.org/_X4xYjzHU6d91

You could also download the program from the following website:

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.

auto_fit

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?