Detect those pesky kids before they get to the front door.
Put
it outside to spook the Trick-or Treaters as they walk up to your door. This project is motion activated using a
PIR sensor, upon activating the Owl and some cheap LED string lights turn on.
Step 1. Prototyping
I built the circuit on a breadboard to test the idea. I used the PIR sensor and breadboard from the brilliant
CamJam EduKit 2. I used transistors to drive the LED’s as the
Raspberry Pi GPIO pins cannot supply a lot of current. The code was written in Python using the
great GPIO Zero API. I set the Python script
to load on start-up.
GPIO Connections
GPIO 4 - PIR sensor
GPIO 5 - Owl via driver transistor
GPIO 6 - Bat lights via driver transistor
GPIO 12 - Hand lights via driver transistor
GPIO 17 - Shutdown switch
Step 2. Transferring the circuit onto a PCB
The circuit
worked well so I decided to transfer the breadboard prototype onto a more permanent Adafruit Perma-Proto HAT.
Step 3. Building into an enclosure
While looking for
suitable enclosures in Poundland I came across a nice plastic pot full of
Halloween sweets, having removed the sweets to eat later. I set about cutting some holes in the pot for
the PIR sensor and 3.5mm mono jacks. I
connected all of the cables and checked that it worked.
Parts List:
1 x Raspberry Pi
board, any model will work
3 x NPN
Transistors
3 x 10KΩ Resistors
3 x Suitable resistors for the LED’s ( I used 22Ω resistors)
1 x PIR Infrared Motion Sensor (HC-SR501)
1 x PCB tactile switch
3 x 2 way Molex KK type 2.54mm headers and housing
1 x 3 way Molex KK type 2.54mm headers and 2 housings
Some cheap Halloween lights from Poundland
Complete code listing:
Complete code listing:
- from gpiozero import *
- from subprocess import check_call
- from signal import pause
- import time
- pir = MotionSensor(4)
- owl = LED(5)
- bat = LED(6)
- hand = LED(12)
- owl.off()
- bat.off()
- hand.off()
- print("waiting for pir to settle")
- pir.wait_for_no_motion()
- while True:
- print("ready")
- pir.wait_for_motion()
- print("motion detected")
- owl.on()
- bat.blink()
- hand.blink(2,2)
- time.sleep(30)
- owl.off()
- bat.off()
- hand.off()
- def shutdown():
- check_call(['sudo', 'poweroff'])
- shutdown_btn = Button(17, hold_time=2)
- shutdown_btn.when_held = shutdown