Automated Halloween Display Using a Raspberry Pi
3241 Views, 10 Favorites, 0 Comments
Automated Halloween Display Using a Raspberry Pi
I love Halloween!
It's my favorite season and also love playing with my Raspberry Pi. What better way to combine the two than to automate my decorations to make them extra scary.
I had found one or two tutorials online and youtube videos of others that had tried similar things but none of them matched what I wanted to do. Most of them used normal power (220V) and solid state relays to turn on and off lights etc. This was something I wanted to avoid for safety reasons as I wasn't comfortable with playing with 220v of power incase something would overheat or someone could touch a surface not properly insulated.
For this reason I decided to use battery power with the exception of the raspberry PI itself. I wanted the following to feature in my display.
I wanted a strobe light in the background to make a lightning effect accompanied by a thunder sound track in the background.I wanted to have a light bulb hanging from the ceiling. When someone enters it trips a PIR motion sensor which starts the sequence.
I will show you how I created my display and how I modified the components I used. Bear in mind though that you can use the same principle to add any battery operated devices to yours.
To start you need:
· Raspberry pi with rasperian installed.
· Breakout board and breadboard.
· Raspberry Pi power supply.
· jumper wires
· Speaker.
· multi core cable (Telephone, cat5 or cat6)
· wire strippers
· Soldering iron and solder.
· Various screw drivers.
You will also need.
· Battery operated Halloween decorations
· Vibration motor(Optional but can be found in old games controllers)
· PIR sensor (Optional)
I will have a video of it uploaded soon.
The Strobe Light
I purchased a battery operated strobe light for 3 Euro in a Halloween store. I opened it up to allow me to modify it.
I traced where the positive and negative wires are coming from the battery compartment to the circuit board. I then soldered two wires into the same points and fed them out through a hole i made in the casing. I then closed up the casing again With these wires connected and the switch turned on, in theory when we apply a voltage to them we should get the strobe light to strobe. To extend the wire back to the raspberry pi I used two single coresfrom a network cable. We will use python on the raspberry pi to control the strobe. More on this later.
Vibrating Monster
I had a monster
decoration that I had bought a number of years ago and I wanted to bring it to life.
In order to do this I got an old games controller and took the vibration motor out of it. Once I had it our I extended the positive and negative wires to allow me to connect it to the breadboard. Again I will be able to turn the motor on and off using python later to make the monster shake.
Lightning
To provide the purple back light I took the battery compartment for a set of battery operated fairy lights and soldered a core of cable to the positive and negative contacts within. This will allow me to turn the back light on and off although I will likely leave it turned on.
Next was the light up pumpkin. I bought a small red LED and resistor and a hollow foam pumpkin. I carefully carved out the face in the pumpkin. I wired the LED to the resistor and soldered two cores of the network cable to allow it enough length to go back to the breadboard.
For the light that will hang from the ceiling I bought a small solar powered light bulb. I opened it up and found where the battery connected into the circuit board. I removed the battery and soldered two wires to these points similar to what I done with the strobe light. Essentially bypassing the switch and battery.
Wiring It All Together
The next step is to wire it all together. You will need to attach a speaker to the raspberry pi for sound. I then attached the breakout board and breadboard to the pi and all the wires feed back into it. I wired a small PIR sensor to the PI so that I could trigger the sequence. I concealed this using some green and grey netting I bought in a decoration store.
The table attached shows how the positive and negative wires for each of the parts of the project are wired to the pins. You will notice the positive is connected to a 3V output and the negative is connected to a numbered pin. To turn this part on we will set the pin to 0 and to turn it off set it to a value of 1. This is the same as completing the circuit or breaking it.
Coding It All
I used Python to
code my display. I have attached my two code files. One of the script files controls the lightning effect and the other runs the sequence when the sensor is triggered. Both of the scripts run automatically at boot up. I followed this Instructable to get the file to run on boot up. If you are not familiar with Python there are loads of really good tutorials online including raspberry pi specific ones on the raspberry pi website.
Note: You will need to google some sound files to go with your setup. I did not upload the files I used here as I did not want to infringe any copyright.
Lightning.py
First to explain what the lighting.py script does. The first thing we need to do is import the modules we will need. We need time, pygame (allows us to play sounds), RPi.GPO ( GPIO pins) and random (so we can generate random numbers)
Next we initialise the pygame module and we need to specify what GPIO numbering system we will use. This site here explains it pretty well. https://raspi.tv/2013/rpi-gpio-basics-4-setting-up... You also need to tell Python what pins are inputs and what are outputs.
We then load and play the thunder sound and start a loop. Within the loop we turn the strobe on for a random amount of time and off for a random time. This will simulate the lighting. You can play around with the values for the times but I feel to simulate it properly the time the light is off should be longer than the time on.
Halloween.py
Similar to the last script we need to import the modules we need and initialize pygame. We also need to specify the GPIO numbering and import the sounds we need.
The next thing I did was to set variable called triggeredTime with the current time. This is like a starting point before we start the loop which will check for an input from the sensor. I specified in the loop that the loop should only run while the value of triggeredTime is less than the current time. If the sensor receives an input the sequence will run which sets the value of triggeredTime to to the current time + 60 seconds. This will mean that once the sequence is finished the loop wont check for a sensor value for another 60 seconds.
Within the loop we set the initial values of the bulb the pumpkin and backlight. it then checks the value of the sensor. If it's 0 it resets the value of the pins. If the value is 1 it plays the demon girl voice and sleeps for 22 seconds. Then it plays the sound of a bulb sizzling. We also create a count variable to be able to make a while loop for the bulb. The while loop runs while the value of count is less than 9. Each time the loop runs it randomly turns the bulb on and off and increments the count value by 1.
When that loop is finished it plays the sound of the bulb blowing and the bulb goes off. Next we have another loop that loops 3 times and vibrates the monster monster for random times.
At the end we have a keyboard interrupt which resets all the pins.
Enjoy
Enjoy what you've
created and remember you could add any battery operated part to this display and edit the code sequence as you would like.
If you have any questions just ask!