Raspberry Pi-powered ghosts will haunt your house on Halloween
Learn how to create a fully automated ghost show that you can project on any screen — or the walls of your house.
By Swapnil Bhartiya, CIO
I have been busy playing with Raspberry Pi, Arduino board and electronics lately. I have been building projects for Halloween as my 4 year old son is super excited about it. We created a graveyard scene in our back patio and installed a projection system that runs a spooky projection show featuring ghosts and spirits hanging out in the graveyard. This project is about building a fully automated projection system using Raspberry Pi, Linux and open source scripts. I purchased special effects videos from AtmosFX, but you can create your own spooky videos.
First we need to install Raspbian (a Linux based operating system) on our Raspberry Pi. The easiest way is through NOOBS. Download NOOBS from the official site. I am assuming you are either using Linux or macOS because these two platforms come with the Terminal app that allows users to perform many tasks from the command line. If you are a Windows user, then you can use Putty to manage your Pi remotely.
Plug in your microSD card to your PC and format it as FAT32. Unzip the content of the downloaded NOOBS file and then copy them to the microSD card. Make sure that you have copied the content of the NOOBS directory to the microSD card. When you open the microSD card, you should see all files as seen below:
Insert the microSD card into the Raspberry Pi, connect the monitor through the HDMI cable, connect keyboard & mouse and plug in the 5v power supply. The Pi will boot into NOOBS and you will see this image.
I recommend connecting to the Wifi so that you get updates images. Once connected, it will show the latest operating systems for the Pi; choose Raspbian on the top and let NOOBS install it for you. It may take a while. Once Raspbian is installed reboot your system:
(Note: The password for pi is ‘raspberry’).
Once you boot into Raspbian, first connect to the Wireless network using the Wireless option on the top bar. Now find the IP address of your system as we will be doing the rest of the installation and configuration remotely. Run the following command in the terminal:
Note down the IP address showed in the ‘wlan0’ section.
In my case it was 10.0.0.124. Once you have the IP address, open the terminal app on your macOS or Linux system (if you are on Windows, you can use Putty). Then ssh into the Pi:
When asked, enter the password for pi that is ‘raspberry’. Now you can control and manage your Pi, remotely from any PC in the local network. If you want, you can unplug the keyboard; just leave the monitor attached as we need to verify that video playback is working OK.
Let’s first update Raspbian:
sudo aptitude update
sudo aptitude dist-upgrade
(Important Note: From now onwards, all of these commands are being run from a remote machine using the ssh protocol)
Automate the video playback
Since we are going to create a projection show, I wanted to automate things as much as possible. My desired solution was that the horror show will start as soon as the Raspberry Pi boots up; I didn’t want to open the file and play it in a media player. I found a great open source script called Video Looper. It plays selected videos in fullscreen mode automatically.
First we clone the Video Looper repository from GitHub onto our Raspberry Pi.
Once the script is installed, you will notice that the monitor hooked to the Pi goes blank and a message to insert USB drive is displayed. Which means our script installed properly.
We now have to make some changes to the Video Looper scrip. By default Video Looper needs a USB flash drive plugged to the Pi in order to play videos; we are going to change that. We will edit the ‘video_looper.ini’ file to make desired changes. Open the file in the terminal with preferred editor:
sudo nano video_looper.ini
Scroll down in the file and find the section where it says:
file_reader = usb_drive
#file_reader = directory
Since we are not going to use USB, comment the first line and uncomment the second line, so it becomes like this:
#file_reader = usb_drive
file_reader = directory
Then we are going to disable the information that’s displayed before videos are played. Find these lines :
osd = true
#osd = false
Then disable osd (on screen display) so it will look like this:
#osd = true
osd = false
We now need to provide Video Looper with the path of the folder where videos will be stored for playback. Find this line and add the path to the ‘Videos’ folder so it looks like this:
# The path to search for movies when using the directory file reader.
path = /home/pi/Videos/
Now we have to copy our spooky videos to the ‘Videos’ directory. It can play a few video formats including .mp4 and I heavily recommend using mp4 format. Just copy the desired video files to the Videos directory of the Pi. You can either plug in a USB drive with videos on it and copy them to the Videos directory or use the ‘rsync’ command on Linux and macOS systems to copy files from the local machine to the Pi over wireless.
I use the rsync command as it’s much easier. I saved the mp4 files that I wanted to copy to the Pi in the ‘movies’ folder inside theHome directory of my Fedora system. The following command copied all mp4 files inside the movies folder of my local machine to the Videos directory of the Pi.
If you want, you can reboot your Pi to check if the videos are playing automatically.
Add a shutdown button to the Pi
We need to make one final adjustment to our project before we install our system outdoors for the show. Raspberry Pi doesn’t come with any physical button that allows us to easily shut it down properly. Since we will be installing our projector set-up outside I wanted anyone in my family to be able turn it on and off. You can’t just unplug the power cable from the Pi as it will corrupt the sd card. We are going to use a simple script written by Inderpreet Singh to add a shutdown button to our Pi.
First we need to configure a GPIO pin of Raspberry Pi that can be used to trigger the shutdown command. SSH into your Pi and create a folder called ‘Scripts:
Now cd to this folder:
Then create a file with nano editor:
Copy the following code into that file
# Simple script for shutting down the raspberry Pi at the press of a button.
# by Inderpreet Singh
import RPi.GPIO as GPIO
# Use the Broadcom SOC Pin numbers
# Setup the Pin with Internal pullups enabled and PIN in reading mode.
Save and close the file. (In nano you use Ctrl+x and then type y to save the file.)
Here we are using the GPIO pin #21 as it’s next to the ground pin and I don’t use this pin in my other projects, including the Spooky Halloween music and light show. Now we need to set this script to run as root:
sudo python stop_pi.py
Use two jumper cables and plug into the pin #21 and GND. Then connect these wires to a push button.
Now you can try to push the button to verify that the system will shut down. If it works, reboot the system and log into the system via ssh again as we still have some work to do. First of all we need to make sure that the script runs at system boot.
Edit the ‘rc.local file to add the command that starts our shutdown python script, ‘sudo python /home/pi/Scripts/stop_pi.py &’.
sudo nano /etc/rc.local
Now add the command for stop script before the ‘exit 0’ line, so it will look like this:
# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
printf "My IP address is %sn" "$_IP"
sudo python /home/pi/Scripts/stop_pi.py &
That’s all. Our setup is fully automated. Now plug in the projector to the HDMI port of the Pi, connect a speaker and install your setup where you want the projection to happen.
Enjoy your freaky Halloween show and good luck scaring your neighbors.