Raspberry Pi Halloween Lights and Music Show

by noelportugal in Circuits > Raspberry Pi

34738 Views, 80 Favorites, 0 Comments

Raspberry Pi Halloween Lights and Music Show

DSC_0233.jpg
This year my house was illuminated and animated by spooky music thanks to the Raspberry Pi. Back in 2009 I created what I called the x-mas box which housed 8 solid state industrial relays connected to an arduino. For this year I repurposed the box and used the Raspberry Pi instead. The lights and music where triggered by a PIR motion sensor.

The show was part of my SMS Magic Mirror with Automatic Candy Dispenser project (Instructable not ready yet, stay tuned).

Materials

RaspberryPi.jpeg
ID801_LRG.jpeg
pir.jpeg
ls8646-2.jpg
DSC_0004.JPG
flood_lights.jpeg
holder.jpeg
speaker.jpeg
02360204.zoom.a.jpeg
  • Raspberry PI
  • USB Wifi dongle
  • Adafruit Rapsberry PI prototyping board
  • PIR Motion Sensor
  • Solid State Relays
  • 4 Flood lights
  • 4 Flood lights sockets
  • 1 Strobe light
  • PVC pipe elbow fitting
  • Speakers
  • Cables

Hardware Setup

IMG_2209.JPG
IMG_2210.JPG
IMG_2204.jpg
DSC_0027.JPG
IMG_2196.jpg
IMG_2189.jpg
IMG_2188.jpg
IMG_2202.JPG
Check out instructions on how I build the x-mas box here.

For this project I decided to only use 4 of the 8 solid state relays. I connected them directly to the RPI GIO ports and ground. I used the PVC pipe elbow fitting to limit the radius the motion sensor had. This helped to reduce "false positive" triggers since the PIR motion sensor can be quite sensitive.

I used a long cable to let me place the motion sensor close to the ground (the ssr box was placed on the balcony).

Thats basically it. I used the RPI GPIO ports
  • 17 strobe light
  • 18,21,22 flood lights.
  • PIRmotion sensor
    GPIO 23
    3.3v
    Ground

I placed the 3 flood lights on the second floor deck pointing upwards to allow reflection on the walls. The strobe light was placed in the first floor and it was turned on during the whole song duration.

I connected a set of powerful speaker into the RPI mini-jack audio out.

Software Setup

python-logo.gif
The program is made with Python and is pretty straight forward. I created functions defining each channel (on/off) and just loop the functions while the mp3 was playing. This was really nice since I used python's "subprocess.Popen" and allowed me to poll the process and know when to stop. The lights danced as long there was music! 

I added 5 mp3 songs and they played on a random order.


#!/usr/bin/env python

from time import sleep
import os
import RPi.GPIO as GPIO
import time
import subprocess
from random import randint

GPIO.setmode(GPIO.BCM)
GPIO.setup(23, GPIO.IN)
GPIO.setup(17, GPIO.OUT)
GPIO.setup(18, GPIO.OUT)
GPIO.setup(21, GPIO.OUT)
GPIO.setup(22, GPIO.OUT)

init = True

def all():
        GPIO.output(18, True)
        GPIO.output(21, True)
        GPIO.output(22, True)
        sleep(.3)
        GPIO.output(18, False)
        GPIO.output(21, False)
        GPIO.output(22, False)

def one():
	GPIO.output(18, True)
	sleep(.3)
	GPIO.output(18, False)

def two():
        GPIO.output(21, True)
        sleep(.3)
        GPIO.output(21, False)

def three():
        GPIO.output(22, True)
        sleep(.3)
        GPIO.output(22, False)
        
while True:
        if ( GPIO.input(23) == True ):
		print "Motion Detected"
		if (init == True):
			print "Initializing for 10 seconds"
			init =False
			sleep(10)
		i = randint(1,5)
		song = "/home/pi/" + str (i) + ".mp3"
		reccmd = ["/usr/bin/mpg321", "-q", song]
		p = subprocess.Popen(reccmd, stdout=subprocess.PIPE)
		GPIO.output(17, True)
		while (p.poll() == None):
			all()
			one()
			two()
			three()
			all()
			three()			
			two()
			one()
			all()
			one()
                	two()
                	three()
			all()
			three()
                	two()
			one()
                	one()
			two()
			three()
			one()
			two()
			three()
			one()
			two()
			three()
			one()
			two()
			three()
		GPIO.output(17, False)
                sleep(5);
        sleep(30);