- Learn Linux
- Learn Electronics
- Raspberry Pi
- LPI certification
- News & Reviews
My kids love trick and treat at halloween, but it's a little bit predictable. You find a house down your street with a lit pumpkin, knock on the door and get sweets. Then move on to the next one. Get home and then the kids make themselves ill by eating too many sweets.
Together we decided that this year we'd do something different and give the local kids something to talk about. Inspired by your typical ghost train and a Raspberry Pi we thought surely there is something we could do using creapy sounds and flashing lights.
You can see what its like from this YouTube video.
We went for a door bell as the trigger. This is cheap and easy to implement and means that we don't need to worry about getting a waterproof sensor. Plus it adds an additional scare factor as it starts when their finger is still on the button. Once pressed we have the following events:
Rather than connect direct to the Raspberry Pi GPIO there is a Piface digital board on the Raspberry Pi. This protects the Raspberry Pi from signals that could damage it and makes it easier to switch the relays etc.
The switch connects straight to one of the Piface input pins (then to 0v). The pumpkin to one of the relays on the piface (the other I thought of using for a fan which can only be used during dry weather - but doesn't look like I'll have the opportunity to try it this year) and then the output ports were used for the LEDs and the home automation.
The Raspberry Pi inclues a usb wireless dongle which allows me to make adjustments after install. I have found this useful in tweaking some of the sounds after install as some were found to be too quiet.
The indoor lights are switched on and off using a home automation remote control. This is a safe way that the Raspberry Pi can switch mains electricity without needing to perform any direct connection to the mains wiring.
The same control is used for the flashing disco lights in the garage, but using a different button on the remote control. I have also included an indoor lamp that uses the same channel / button as the disco light so that we know when there is someone at the door before they ring the normal door bell.
These are some of the scary sounds that I used:
One issue I had was with the volume of these. In particular the creaking door was not loud enough to hear. I edited the sound files in Audacity to increase the volume.
Audacity should work on the Raspberry Pi, but it is not straight forward to install and some people have had issues. In my case I used Audacity on my Linux laptop, but you can also run it on Windows if you prefer.
The Raspberry Pi was kept outside so as to minimise the number of cables that needed to go into the house. I did however run a power supply from the garage (it could have been run off batteries instead) and a long audio cable extension into the garage to connect to the speakers.
To keep the Raspberry Pi and the electronics safe it was stored in a weatherproof electrical box. These are ones that I use for the outdoor Christmas lights later in the year. I used two boxes one for the Raspberry Pi and one for the USB mains power supply plug, although this could have been combined into one at a squeeze. The power supply went between the two using a long USB extension lead.
The other electronics, the LEDs and the pumpkin were not quite so fully waterproof, but as they are low voltage and less expensive I risked having those outside with just some "gaffa tape" to try and keep the rain out. They were only installed for two days so I was hopeful it would be enough. It mostly worked although I did have problems with one LED see later.
The code to make this work is written in python. The Piface board is triggered using the pifacedigitalio library which is included on the standard NOOBs install. It does require the appropriate SPI kernel module to be enabled which can be done through raspi-config on the latest NOOBs image or details are provided in the Raspberry Pi home automation project.
The sounds are created using the pygame module, normally used for creating graphical games. This has the advantage of being simple to code and runs in the background allowing the rest of the code to keep on running.
#!/usr/bin/env python # Updated code for Haunted House using PiFace digital # See http://www.penguintutor.com/electronics/halloween from time import sleep import pifacedigitalio import os import pygame # Time that the button is pressed for BUTTON_PRESS_TIME = 0.5 # seconds PUMPKIN = 0 LED_1 = 2 LED_2 = 3 DEVICE_1_ON = 4 DEVICE_1_OFF = 5 DEVICE_2_ON = 6 DEVICE_2_OFF = 7 def main(): # Setup PiFace pifacedigitalio.init() piface = pifacedigitalio.PiFaceDigital() pygame.mixer.pre_init(44100, -16, 2, 2048) pygame.init() # load music files snd_door = pygame.mixer.Sound('/home/pi/halloween/door1.wav') snd_light = pygame.mixer.Sound('/home/pi/halloween/lightbulb.wav') snd_scream = pygame.mixer.Sound('/home/pi/halloween/screams.wav') snd_doorbell = pygame.mixer.Sound('/home/pi/halloween/doorbell.wav') snd_monster = pygame.mixer.Sound('/home/pi/halloween/monstersong.wav') print "Halloween ready" print "Waiting on button press" while(1): if piface.input_pins.value == 1: print "Button pressed" snd_door.play() flash_light_seq(piface) sleep(3) snd_light.play() sleep(0.2) print "Light off" mains_switch(piface, DEVICE_1_OFF) sleep(1) snd_scream.play() flash_lights(piface) print "Light on" mains_switch(piface, DEVICE_1_ON) snd_doorbell.play() sleep (9) print "Disco lights on" mains_switch(piface, DEVICE_2_ON) snd_monster.play() sleep(40) mains_switch(piface, DEVICE_2_OFF) print "Waiting on button press" sleep (0.2) def flash_light_seq(piface) piface.output_pins[LED_1].turn_on() sleep(0.3) piface.output_pins[LED_2].turn_off() piface.output_pins[LED_1].turn_on() sleep(0.3) piface.output_pins[LED_1].turn_off() sleep(0.5) piface.output_pins[LED_1].turn_on() piface.output_pins[LED_2].turn_on() sleep(0.5) piface.output_pins[LED_1].turn_off() piface.output_pins[LED_2].turn_off() sleep(0.4) piface.output_pins[PUMPKIN].turn_on() sleep(0.4) piface.output_pins[PUMPKIN].turn_off() sleep(0.4) piface.output_pins[LED_1].turn_on() piface.output_pins[LED_2].turn_on() sleep(0.3) piface.output_pins[PUMPKIN].turn_on() def flash_lights(piface): for i in range(0,3): flash_light_seq (piface) sleep(3) piface.output_pins[LED_1].turn_off() piface.output_pins[LED_2].turn_off() sleep(2) piface.output_pins[PUMPKIN].turn_off() sleep(0.5) def mains_switch (piface, port): piface.output_pins[port].turn_on() sleep(BUTTON_PRESS_TIME) piface.output_pins[port].turn_off() if __name__ == "__main__": main()
This is a fairly simple project to implement, but adds a whole new dimension to trick or treat. I've updated this page with details of how it goes on the night below.
The Haunted House was set-up for two days. The first was for a Halloween party which had some of my children's school friends visit and the second was Halloween itself on the following evening. Unfortunately I was not able to get any video of the guests arriving, but I did note down a few of their reactions.
On the party night it all worked well, although by the end of the night I decided that the sequence was too long and had a while with not too much happening. I therefore moved some of the flashing lights (LEDs) earlier in the sequence when the creaking door sound was playing and shortened the sequence later instead.
Whilst the Raspberry Pi and circuit was kept waterproof water did manage to get on to one of the LEDs which stopped working on the second night. The rest still worked OK though so it wasn't too big a loss.
The party night was mainly friends and they did comment about liking the display. Some of the friends are in the Code Club sessions I'm running and they were interested in knowing whether they'd be using the same Raspberry Pi in their next session. One of them most likely will, but I have bought dedicated SD cards for Code Club so they won't actually be any of the sounds / code on the SD card they use anyway.
This is one of the great things about the Raspberry Pi, as that particular Raspberry Pi is also used for controlling a Robot vehicle and for the Code Club sessions. It's easy to change the configuration of the operating system by just swapping an SD card.
We didn't have too many visitors on Halloween itself. Perhaps the weather had put many off (although it did stay dry for most of the actual night it had been raining during the afternoon). I certainly had some good comments. Some liked the added twist for Halloween and some found it funny. I didn't get any negative comments except for one little girl. She was only 3 years old and she said [in a rather cute voice] "I'm scared of your monsters". I hope she wasn't too upset by it, her older sister seamed to enjoy it.
Please view the copyright information regarding use of the circuits.