This is Part 2 of the Micro:bit version of the someone behind you sensor.
For those who did part 1, this one adds an addressable LEDs to indicate when the PIR motion sensor is triggered. It also has a secondary nightlight mode that turns on the LED strip for approximately 60 seconds.
This project is a complete system. So, you do not have to go and build Part 1 if you do not want to.
Now let’s gather all the necessary components you’ll need to build this project.
If you already have Part 1 done, skip to STEP 6. If not... continue one directly.
Lay the Micro:bit and Kitronik Inventor’s Kit on a table. Insert the edge-card end of the Micro:bit into the Inventor’s Kit socket.
Prepare the 9V power supply. I used a 9V power supply from an old device, I think a router. But, there are better versions you could use. Like the one here at element14. You will have to splice the ends into some project wires.
I sliced the 9V positive to the LED strip’s positive voltage line. I am using this separate power supply to drive the power hungry LED strip directly. If you don’t do this, you project is going to get really hot, and eventually destroy itself.
Wire up the PIR sensor, as shown in the picture. I used colors to indicate power (RED), ground (BLACK), and the signal (BLUE).
Attach the PIR sensor’s GND wire to one of the Kitronik Inventor’s Kit breakout pins labeled 0V, that’s a ground. Connect the signal line to the pin labeled P0. This is an analog input.
Follow the schematic below:
Connect the PIR Sensor's signal line to pin A0 on the breakout board.
Connect the 9V power supply’s positive leads to the PIR sensor directly. Then plug the 9V power supply’s ground to another of the Kitronik Inventor’s Kit 0V grounds. To complete a circuit like this, you must share grounds between the power supplies.
A side note: Why do we need to do this? The PIR sensor needs an input voltage of between 5V and 20V, the Micro:bit can only provide a 3.3V source to external devices. Also, Part 2 of the project has addressable LEDs, and we will need a beefy power supply for those.
Attach the 9V positive power to the PIR Sensor directly:
Connect the 9V power supply ground, negative, to the 0V pin on the Inventor's Kit breakout board.
Attach the LED strip’s GND to another 0V pin on the Kitronik’s breakout board. Then connect the CLOCK line (yellow) to PIN 13 on the breakout board. And connect the DATA line to pin 15 on the breakout board.
STEP 7 (Optional)
Roll some construction paper into a tube big enough to house the PIR sensor. Point the white dome of the PIR sensor towards one end of the tube. What this is doing is narrowing the field of view for the PIR sensor. You could leave the PIR sensor outside of the tube, sure, but it has a near 180-degree field of vision. You’ll be triggering it with anyone moving in half the room!
Plug the MicroUSB cable into the Micro:bit, and plug the other end of the cable to a PC or MAC.
At this point, you are going to copy over the code to the Micro:bit. I am providing the program (code) in this posts that needs to be copied over.
I had to pack it up in a ZIP file called PART 2 Microbit motion project.zip. Unzip it. The file you need is called "PART 2 Microbit motion project.hex"
When the Micro:bit plugs into a computer, it shows up as a USB flash drive. All you have to do is copy the file, "PART 2 Microbit motion project.hex," over to the Micro:bit, like it’s a USB Flash Drive.
The Micro:bit will reset, and the program is active.
You could leave it plugged into your computer, or use that 5V USB power adapter to make the project a bit more mobile.
It should look like the following. The first half is the multicolor fading. The second part is the nightlight mode.
Applications of this project are left to your imagination.