Introduction: Raspberry Pi Motion Activated Transparent Screaming Ghost for Halloween

About: At various points in my life I was an engineer, programmer, biophysicist, and physician. Now I look at people's insides without having to cut them open. I also like to tinker for fun.

Greetings. Please bear with me as this is my first Instructable. However, I have built this effect for this last Halloween and have had some pretty good results with it. So I thought I'd share.

Videos and pics of my test setup for this effect, as well as my entire Halloween setup for 2014 are at the following link: https://goo.gl/photos/aEG3HtFUVeJmWEsz9

UPDATE: This is also the project that was mentioned in the October 2015 issue of Popular Science (page 67).

Introduction

The video above demonstrates the effect. The basic setup uses a projector, a PIR motion detector, raspberry pi, and a piece of plexiglass with a thin spray coating of reflective paint. A loud, startling transparent image appears when a person walks in front of it. I will go over the steps and shell script code used in creating this effect.

The following steps will outline the creation of each of the components of the effect and some possible alternatives.

Step 1: The Transparent Screen

Materials

Plexiglass or Lexan (as large as you need). May be purchased at a place like Home Depot or Lowes.

Reflective spray paint (such as Reflect-All, Rust-Oleum 214944 Reflective Finish, or Night Brite). These are a little harder to find in most of the brick and mortar stores and you may have to go online. Alternatively, you can try a very thin/sparse coat of glass frosting spray paint, which is easier to find.

Wood pieces for frame. I happened to have some left over baluster pieces from a deck project.

Build

Screen - Lay the clear screen down on a tarp and spray a very thin layer of paint over one side of the screen. You do not need much paint at all. I essentially tried to mist on the paint from a good height in order to get a nice sparse, relatively uniform layer. Try practicing first on some cardboard or scrap pieces to get the technique down before spraying onto the screen. Ideally, your screen should remain transparent and nearly clear.

Frame - A large piece of plexiglass is likely too floppy to stand well without a support frame. Lexan (polycarbonate) is stiffer but may be more brittle (and is typically more expensive). You can either build a standing frame or hang the screen from an overhead support. I had to build a standing frame, since I was using this effect outdoors.

I bolted together some leftover deck rail balusters that I had laying around, as shown in the picture above. The screen is sandwiched between pairs of supports at the bottom and side(s) and tightened with bolts drilled through the support pairs. The support legs at the bottom are also drilled and bolted to one of the bottom supports, as shown. Right angle brackets have been screwed into the side and bottom supports.

Alternatives

(Edit) Window Screen - After a few years of use, my 6 foot plexiglass screen developed a few cracks and a few minor breaks, it was also prone to being blown over by the wind on windy Halloween nights. So I thought of a new cheaper, lighter, more wind tolerant alternative... a white mesh window screen. I was able to get some white garden netting from Amazon. and use it with something like a DIY screen frame from Home Depot to create a new transparent projection screen. I had reconfigured my original wooden frame to accommodate the new screen and used it this for Halloween this year. It worked perfectly.

Theatrical scrim - or any type of thin semitransparent gauzy material hung from a doorway or other support. In the right light (ie. backlight), this should be pretty transparent from the front but still act as a good medium to project a ghost onto. This is used to good effect in this YouTube video. More detailed video instructions are here.

TransScreen - Used in movies and advertising. This is the type of screen my project is trying to simulate at a much cheaper price.

Fog Screen - If you are really ambitious, this is a great effects screen and several people have posted their own builds:

Step 2: The Raspberry Pi

Materials

For this project, I used a Raspberry Pi Model B with a PiFace module. However, you can use any Pi for this project.

The PiFace Module- is optional, since you can interface to the GPIO pins directly or create your own breakout board easily. The PiFace is simply an add-on board for the Pi which gives it some interactive features including separate input/output ports with screwblocks, 4 pushbuttons and 2 relays. I'm not sure how well the current PiFace fits on top of the newer Pi Model B+, although this table seems to indicate that it should still work.

(EDIT) For those of you that have been asking me how to create this effect without the PiFace board, please read me outline in the Comments section below.

The Raspberry Pi - is basically any RasPi running Raspbian or other flavor of linux. Access to the GPIO pins is via the WiringPi library, with instructions for downloading and installing found here. The main code used for this effect is simply a bash shell script which uses the the command-line gpioutility the control to access the GPIO pins on the pi.

The pi should also be configured to output its sound through the 3.5 mm jack rather than the HDMI interface.

The source videos are played by omxplayer on the RasPi and should be encoded into a format compatible with this player.

Step 3: Ancillary Components

Materials

Video Projector - Needs a high brightness (lumens) level for projecting onto a semitransparent screen. An HDMI interface is the easiest way to connect this to the RasPi. Otherwise you will also need an HDMI to DVI convertor cable.

Tripod - Optional but helpful in aligning the projector.

Passive IR motion sensor - Necessary for motion triggering of the effect. These can be purchased from Amazon (https://www.amazon.com/DIYmall-HC-SR501-Motion-Inf....

Powered speaker - Can be wired or wireless. Power can be via batteries or power supply. For best effect this should be hidden but as close as possible to your projection screen. This should also be as loud as possible to add to the "startle factor" when the screaming ghost effect is activated. In the next section (Cabling), I'll discuss how to get sound and power to your speaker over the distance between the RasPi / projector and the screen / speaker.

Source Video - I used the Ghostly ApparitionsDVD from AtmosFearFX, which contains numerous ghost effects for projecting onto a window or wall. This can be purchased on-line, although the Spirit pop-up stores, which appear around Halloween, did actually sell these videos this year. However, you can pick an alternative source for your videos.

The Ghostly Apparitions DVD includes ghost effects which are shown sideways for projecting apparitions in portrait (rather than landscape) orientation, with the projector oriented sideways. This is the way I had set up my own effect.

However, a DVD is insufficient to create an effect which is motion activated. Therefore, I needed to convert the videos I needed into digital format which could be played by omxplayer on the RasPi. I recently noticed that the company has started offering individual digital downloads of their video effects. In my case, I started with the DVD as the original source and used one of the free DVD ripping programs to extract MP4 versions of the specific videos I needed. For the "startle" videos I also had to edit out a second or two of blank space at the start of some of the videos to make them start up more suddenly on motion activation.

Step 4: Cabling

The Cabling

The main issue with this effect effect are that the projector and screen have to separated by a distance. The PIR motion sensor and speaker have to be close to the semitransparent screen and the RasPi has to be close to the projector (unless you have a really long HDMI cable, which can be expensive). So you need several long wires to carry signals back and forth from the pi to the screen. These include:

  • PIR sensor - Three wires (VCC, Trigger and Ground)
  • Audio signal - Mono audio (two wires) or stereo audio (three wires). Optional if you are using a wireless speaker.
  • Speaker power - Two wires, depending on how you are powering your speaker. Optional of you are using battery powered speakers.

So, depending upon your setup, you need between three and eight long wires to communicate between the two ends of the effect. In my case, realized that a Cat 5 or Cat 6 network cable could carry all these signals over a good distance. Rather than cut up a perfectly good network cable, I created my own RJ45 jacks at the RasPi and screen/IR sensor ends of the setup. So long as you keep a consistent color scheme between the two ends, you should be able to connect the two ends with a normal cat 5 or cat 6 cable.

My own wire color scheme, as shown in the pictures above, was as follows:

  • Orange/white - PIR sensor trigger - Connects to PiFace input port 7.
  • Orange - PIR sensor VCC (3-5 volts) - Connects to PiFace +5V
  • Green/white - Speaker power (In the picture above I am sending some of the 5 volt PiFace power to a microUSB jack.)
  • Green - Speaker ground
  • Blue/white - Audio right - Connected to a 3.5 mm audio jack which plugs into the analog audio output of the RasPi.
  • Blue - Audio left - Connected to the 3.5 mm audio jack
  • Brown/white - PIR Sensor ground - Connects to PiFace Ground
  • Brown - Audio ground - Connected to the 3.5 mm audio jack

At the screen end on the effect, I soldered the three PIR wires to a three pin header, which I could use to connect to the sensor with a three-conductor cable. The three audio lines are soldered onto a 3.5 mm audio jack, which can be plugged into the AUX input of the powered speaker. The external power lines are soldered to a 2-pin screw terminal block. In the picture above, the 5 volt power wires of a microUSB connector are also screwed into the screw terminals.

Cautions

Check your connections. Miswiring with live voltages can potentially fry your electronics. Check for shorts and continuity with a multimeter.

Be careful about how much voltage and current you put over the speaker power wires. Cat 5 wire is typically 24-26 gauge (AWG) and cat 6 is typically 22-24 guage. These can typically carry up to 12 volts over long distances (as in power over ethernet applications), However, be careful about sending big voltages/currents over these lines. You probably don't want to directly power a 50 Watt speaker over this line.

Do not confuse this cable with any real network cable that might be connected to your RasPi. We are simply using the cat 5/6 cable as 8-conductor wire which plugs into your home-made jacks at the proximal and distal ends of your ghost effect.

Step 5: Code (Bourne Shell)

First, let me preface this section by emphasizing THIS IS NOT PYTHON CODE. This is an executable shell script (Bourne shell). Please don't keep writing me in the comments saying that this doesn't run in python, because THIS IS NOT PYTHON!

I won't go into the details about Raspbian Linux commands or writing executable shell scripts in this document. There is plenty of information out there about it. Just remember to change the mode of the final script to make it executable with the chmod a+x command when you are done editing it.

When I extracted the video video files, they were named after the corresponding track number from the source DVD with a .mp4 extension. On the pi running Raspbian, the extracted and edited videos were transferred to a subdirectory called Video under the default user (username pi).

I wrote a simple bash shell script which uses the gpio command from the WiringPi library to continuously read the GPIO pin connected to the PIR sensor and to read the 4 tactile buttons on the PiFace board. The executable shell script is named scareme and is located in the home directory for user pi.

Notes

The library and gpio utility do support the PiFace addon board. You access the PiFace GPIO pins by adding 200 to the pin number. The script also utilizes the Piface's four tactile input buttons (i/o pins 200 to 203). The code defines the input buttons as follows:

  • 200 - Manual trigger
  • 201 - Volume up
  • 202 - Volume down
  • 203 - Switch video set. The button switches between 3 different sets of videos which can be used for the effect (not scary, scary, and extra long)

In the script, the tactile buttons are initially set up to use the board's built-in pull-up resistors. Therefore, reading the input value for the button is always 1 until someone presses a button and switches it to 0. (Hence, the inverted logic for reading these pins).

scareme script

#!/bin/bash 
# Detect motion on PiFace and play scary video.

# Define PiFace Pins
MotionPin=207 
TriggerPin=200 
VolUpPin=201 
VolDownPin=202 
ModePin=203

Volume=1500
Volstep=50 
CurrentState=0 
CurrentMode=0

DoFlip="" 
# If you need to flip the video upside down, uncomment the following line
# DoFlip="--orientation 180" 

# Assign numbered videos to one of three video modes. Also define the order in which the videos appear
VidMode=0 # 0=Not Scary, 1=Scary, 2=Extra Long 
VidOrder[0]="14 30 46 62" 
VidOrder[1]="12 32 44 64 16 28 48 60" 
VidOrder[2]="6 22 38 54" 
PriorVid=$VidMode 

# Use piface internal pullup resistors on tactile button pins 
gpio -p mode $TriggerPin up 
gpio -p mode $VolUpPin up 
gpio -p mode $VolDownPin up 
gpio -p mode $ModePin up 

# Main Program Loop 
clear
while : ; do 
  for i in ${VidOrder[$VidMode]}; do 
    if [ $VidMode -ne $PriorVid ] ; then echo -ne "Video Set $VidMode\r" ; PriorVid=$VidMode; break ; fi 
    while : ; do 
      PriorState=$CurrentState 
      PriorVolume=$Volume 
      PriorMode=$CurrentMode 
      let "CurrentState=(! `gpio -p read $TriggerPin`) | (`gpio -p read $MotionPin`)" 
      let "Volume += ( (! `gpio -p read $VolUpPin`) - (! `gpio -p read $VolDownPin`) )* $Volstep" 
      let "CurrentMode=(! `gpio -p read $ModePin`)" 
      if [ $Volume -ne $PriorVolume ] ; then echo -ne "$Volume\r" ; fi 
      if [ $CurrentMode -gt $PriorMode ] ; then let "VidMode = ($VidMode + 1) % 3"; break ; fi 
      if [ $CurrentState -gt $PriorState ] ; then 
        omxplayer -b --vol $Volume $DoFlip ./Video/$i.mp4 >> /dev/null 
        clear 
        break 
      fi 
    done 
  done
done

Step 6: Putting It All Together

Hardware Setup

The projector is mounted sideways on the tripod to match the orientation of the screen. Aim the projector at the screen. It is best to aim the projector at an angle with relation to the screen so that the projector light doesn't hit the viewer right in the face when they are in front of the screen.

Connecting the speaker: Either plug in the 3.5 mm jacks to the audio output of your pi and AUX input of your speaker or use a wireless speaker. Make the speaker as loud as possible to add to the "startle" factor.

Run Software

  1. Connect your pi to a USB keyboard and to the the projector via the HDMI
  2. Boot the pi
  3. Enter single-user mode by hitting CTRL+ALT+F1. This keeps the background black while the script is running.
  4. Login as pi with default password raspberry
  5. Run the shell script by typing ./scareme
  6. The program will continue to run until you hit CTRL+C a few times.

Adjustments

I used the manual trigger (tactile button 1) on the PiFace board to manually activate the video at the pi end and make adjustments to the projector. You can also use the buttons to make adjustments to the output volume and to change which set of videos is triggered.

If the motion sensor triggers too soon, you can put a piece of tape over the edges of the sensor to make it less sensitive. The picture shown above shows pieces of tape restricting the sensor view so that it triggers only when someone walks directly in front of the sensor,

In my case I had initially mounted the PIR motion detector onto the frame of the transparent screen, which worked great indoors. However outdoors, the wind caused the frame to move and prematurely trigger the motion detector. So, I moved the sensor to an adjacent, less mobile structure.

Halloween Decor Contest 2015

Second Prize in the
Halloween Decor Contest 2015

First Time Author Challenge

Participated in the
First Time Author Challenge