Security. Cloud. Sometimes transit.

Raspberry Pi Project : Motion Sensor Fortune Teller


Want a unique, possibly creepy little feature for your next dinner party? Install a Raspberry Pi powered fortune teller robot (complete with mannequin head!) in your bathroom! It’s a simple project that involves sensors, text to speech programs, and a fair bit of fun. There’s nothing like having your guests come out wondering why the mannequin head in the bathroom just told them “Don’t go surfing in South Dakota for a while.”


Required are the following parts:

  • Raspberry Pi
  • Solderless Breadboard
  • Wires (six needed, all Male to Female)
  • Passive Infrared (PIR) Sensor Module (Buy from Adafruit or quite cheaper, from ebay)
  • Speakers

Optional parts include:

  • A USB hub (to power multiple things, e.g. speakers)
  • Wireless dongle (for remote control, so you can scare your guests further by having it say their names)
  • A creepy mannequin head


1. Set up the Pi

Install Raspbian : numerous tutorials exist for how to do this, Raspberry Pi has documentation here. Personally, I just have the latest Raspbian img and use the dd command to load it onto the SD card.

2. Set up the PIR sensor

For the actual electronics part of this hack, there also exists quite a few tutorials out there. The best explanation for the hardware process was from a blog post on DataIsSexy. Follow this exactly and you’re in business.

3. Set up the software

And now the fun part of putting it all together. To do this, you can find an awesome write up on using python and the GPIO library for the PIR at Raspberry Pi Spy.   This should be everything you need to get going with using a PIR to trigger an event.

To get the fortune telling part, you’ll need to install fortune and festival by typing the command sudo apt-get install fortune festival .

Festival’s text to speech default install is, how can we say, rough. I’d recommend speeding it down and selecting one of the more natural voice packages.

Fortune can also be hacked to your liking. There’re a number of data files that you can install with fortune giving you seemingly endless quotes to be spoken. I personally enjoyed having it be 50% literary quotes 50% fortunes (the nasty fortunes collection sounds even more fun). The command to do this is fortune 50% literature 50% fortunes .

Now, we just plug this system call into our python script for simplicity (something tells me python has a library to do this as well).

The full code, condensed without comments is:

import RPi.GPIO as GPIO
import time
import os
import datetime
Current_State = 0
Previous_State = 0
    print "Waiting for PIR to settle ..."
    while GPIO.input(GPIO_PIR)==1:
        Current_State = 0
    print " Ready "
    while True :
        Current_State = GPIO.input(GPIO_PIR)
        if Current_State==1 and Previous_State==0:
            print " Motion detected!"
            os.system("/usr/games/fortune 50% literature 50% fortunes | tee -a fortunes | /usr/bin/festival --tts")
        elif Current_State==0 and Previous_State==1:
            print " Ready"
except KeyboardInterrupt:
    print " Quit"

Should be pretty apparent what the command does. The only thing I haven’t mentioned is the tee -a fortunes command. It creates a file (named fortunes) with the text info appended every time the command is called, it’s a way of logging quotes said (in case someone didn’t understand it).


Now just plug it in and set it  and forget it! It’s a fun and easy project. And you could create a simple way of having it say custom commands over an ssh connection (requires wireless dongle and ssh server running) and the command **echo “Hello There!” fortune –tts**