Monday 2 November 2015

Hallowe'en Pis

This year we ended up with three Raspberry Pis powering or controlling our Trick or Treater greeters (scarers).



Spooky Spider

A cheap spider decoration, hollowed out and enhanced with an A+ and a motion sensor that activated  evil red eyes.



The skinny power bank powered the Pi happily for over 4 hours.


The styrofoam body of the spider made it easy to hollow out a cavity for the A+



      



import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BOARD)

# Setup the pins we'll use
GPIO_PIR = 26
GPIO.setup(13,GPIO.OUT)
GPIO.setup(GPIO_PIR,GPIO.IN)
GPIO.setup(15,GPIO.OUT)


print "PIR Alarm active (CTRL-C to exit)"

Current_State  = 0
Previous_State = 0

try:

    print "Waiting for PIR to settle ..."

  # Loop until PIR output is 0
    while GPIO.input(GPIO_PIR)==1:
        Current_State  = 0    

    print "  Ready"     
    
  # Loop until users quits with CTRL-C
    while True :
   
    # Read PIR state
        Current_State = GPIO.input(GPIO_PIR)
   
        if Current_State==1 and Previous_State==0:

            # PIR is triggered
            print "  ALARM!"
            GPIO.output(13,1)
            GPIO.output(15,1)
            time.sleep(5)
            GPIO.output(13,0)
            GPIO.output(15,0)
            # Record previous state
            Previous_State=1
      
        elif Current_State==0 and Previous_State==1:

        # PIR has returned to ready state
            print "  Ready"
            Previous_State=0
      
        # Wait for 10 milliseconds
        time.sleep(0.01)      
      
except KeyboardInterrupt:
    print "  Quit" 
    # Reset GPIO settings
    GPIO.cleanup()

A (cute rather than scary) bat that descended from the porch, also activated by a Pi with a motion sensor and lowered by a stepper motor.


The Pimoroni BlackHAT Hackr and the Pi touch display made is really easy to set everything up on the windowseal so that just the wires from the picoborg board could be passed out through the window to the motor. A shaft adapter and some Lego made a nice winding mechanism.



A sinister Lego skull with Pi-controlled blinking eyes.


Why bother building some supports for the breadboards when you can just wedge the LEDs through the eye sockets. I don't know, kids today, eh?




Ozzy wrote the code for this and I thought the use of a simple random function to control the frequency of blinking was particularly effective and gave the impression of a lurking creature rather than just a thing with regular flashing eyes.

import RPi.GPIO as GPIO
import time
import random

GPIO.setmode(GPIO.BOARD)
GPIO.setup(13,GPIO.OUT)
GPIO.setup(15,GPIO.OUT)


def eyes_blinking(pin1,pin2):
    GPIO.output(pin1, GPIO.HIGH)
    GPIO.output(pin2, GPIO.HIGH)
    time.sleep(random.randint(1,3))
    GPIO.output(pin1, GPIO.LOW)
    GPIO.output(pin2, GPIO.LOW)
    time.sleep(0.2)
counter = 0
while True:
    eyes_blinking(13,15)
    counter+=1
    print ('boo ' + str(counter))

No comments:

Post a Comment