Saturday 8 October 2016

Trick or Treat Detector

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.




















Breadboard layout
























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:


  1. from gpiozero import *
  2. from subprocess import check_call
  3. from signal import pause
  4. import time
  5. pir = MotionSensor(4)
  6. owl = LED(5)
  7. bat = LED(6)
  8. hand = LED(12)
  9. owl.off()
  10. bat.off()
  11. hand.off()
  12. print("waiting for pir to settle")
  13. pir.wait_for_no_motion()
  14. while True:
  15.     print("ready")
  16.     pir.wait_for_motion()
  17.     print("motion detected")
  18.     owl.on()
  19.     bat.blink()
  20.     hand.blink(2,2)
  21.     time.sleep(30)
  22.     owl.off()
  23.     bat.off()
  24.     hand.off()
  25.     def shutdown():
  26.         check_call(['sudo', 'poweroff'])
  27.     shutdown_btn = Button(17, hold_time=2)
  28.     shutdown_btn.when_held = shutdown