Afraid of the dark? Don’t worry! Micro:bit has got you covered. (Or you could just buy a torchlight.)
This tutorial was contributed by Jason Huang of Raffles Institution.
Step 0 – Pre-build Overview
In this project, we will create a light that only lights up when there is someone in a room by detecting motion, using a PIR motion sensor and LED light.
MATERIALS: 1 x BBC micro:bit, 1 x Micro USB cable,
1 x Breakout board, 1 x PIR Sensor, 1 x LED
- Make something with the PIR motion sensor
- Make something which is easily applicable in real life
Step 1 – Components
Insert the micro:bit into the Breakout Board and plug in the PIR sensor into Pin 0.
Plug in the LED to Pin 1. Make sure for both components that the colours of the wires match the colours of the pins.
Step 2 – Pre-coding
We will add a package of code to enable us to use our kit components. Click on Advanced in the Code Drawer to see more code section and look at the bottom of the Code Drawer for Add Package.
This will open up a dialog box. Copy and paste the following link into the Add Package… text field: https://makecode.microbit.org/50544-64675-33322-24641. Click on the search icon or press enter, then click on the Tinkercademy button.
Note: If you get a warning telling you some packages will be removed because of incompatibility issues, either follow the prompts or create a new project in the Projects file menu.
Step 3 – Coding
Click on Tinkercademy inside the Code Drawer to find our custom blocks for the various components in your kit.
For this project, no initialisation is required (woohoo!), and there isn’t much code anyway.
If motion is detected by the PIR sensor, the light is triggered. Or else, the light is turned off. Simple enough.
Step 4 – Success!
Voilà! You have created a simple smart light! Walk into the room and let the be light!