• Published on | Oct 30, 2012 | by FozzTexx

Using a Pi to Keep the Kids Away from the Candy

I thought it would be fun to setup a prop on my porch for Halloween that did more than just sit there. Of course I came up with the idea very late and so this whole thing was cobbled together in just an hour or two. Looking around my house at a ton of the gadgets I had the idea of putting a Jack-o-lantern on the porch that I could control the light in. Searching the internet for scary Halloween sounds caused things to quickly evolve into adding motion sensors, controlling a couple of lights, adding sound, and putting the pumpkin in the lap of a headless scarecrow.

I put a motion sensor at the end of the walk facing the house so that when someone approaches the porch it triggers the computer controlled sequence. First the porch light shuts off, then a scary sound starts playing through a speaker under the scarecrow. The light in the jack-o-lantern slowly brightens just as a "Help Me" emanates from the speaker. Then it dims back down, the sound stops, and the porch light turns back on. I also have a blacklight on the porch that stays on to make sure there is still some light there and to add some atmosphere. The scarecrow is just some old clothes stuffed with lots and lots of plastic shopping bags. I used a tan colored one up at the neck as a sort of flesh tone. 

The whole thing is controlled by a Raspberry Pi with the standard Raspbian setup. The sound is played out the analog jack to a powered speaker that sits under the chair, and the lights are controlled with several X10 modules. In order to control the X10 modules and receive the signal from the motion sensor I use Heyu and a CM11A module connected to a USB serial adapter.

Heyu doesn't come as a package under Debian so you'll need to compile and install it yourself. It's pretty straightforward, but you'll need to adjust the localstatedir during configure:

  $ ./configure --localstatedir=/var
After it compiles and installs, create the /usr/local/etc/heyu/x10.conf by coping the x10config.example and setting the serial port to /dev/ttyUSB0. Also down where the script section is, add the following lines:
ALIAS treater B8
SCRIPT treater on :: /usr/local/bin/treater.sh

Create the /usr/local/bin/treater.sh file as below (or download the attached file) and put the sound file in /usr/local/lib. In rc.local add a line to automatically start the heyu engine. Test it out by sending the ON code that the motion sensor sends. Once the animated sequence is working, put it out on your porch and see how many kids you scare!

#!/bin/sh
PATH=/usr/local/bin:/usr/bin:/bin
export PATH
PORCH=B3
PUMPKIN=B2
WINDOW=B4

if lockfile -! -r 0 /tmp/treater.lock ; then
    echo locked
    exit 0
fi

play -q /usr/local/lib/way_scaryR.wav &
heyu off ${PORCH}
#heyu on ${WINDOW}
heyu bright ${PUMPKIN} 22
sleep 2
heyu dim ${PUMPKIN} 22
heyu on ${PORCH}
#heyu off $(WINDOW)

rm -f /tmp/treater.lock

Media

Join The Discussion

+1  Posted by manganmus • Oct.27.2013 at 18.58 • Reply

This is great - I'm planning on doing something similar for Halloween. I can't get the wav file to play on my Raspberry Pi - is your "play" command aliased to aplay? I can play other wav files that are signed 16-bit 44.1 or 48 kHz stereo, but wav files that are unsigned 8-bit 11.025 or 11.127 kHz won't play (not just way_scary). Any ideas? I've tried converting one of the files to signed 16-bit 8 kHz stereo but still won't work, just gives an occasional popping noise like the others.

+1  Posted by FozzTexx • Oct.27.2013 at 19.29 • Reply

The play command comes with sox, and is in /usr/bin/play

+1  Posted by Mash • Sep.25.2014 at 20.01 • Reply

This is great, I'd like to do this with my kids but haven't worked with the Pi much. Do you have any pics of how the hardware was setup?

+1  Posted by FozzTexx • Sep.25.2014 at 20.06 • Reply

There's not much to show. You just plug the lights into the X10 modules and plug them into the wall.