What is it?
As a child I learnt that to see if a Ghost is present there are a number of elements that can be checked. 1) Is there a sudden drop in the temperature? 2) Are objects moving or being moved? 3) Are the lights turned on and off ?
Pimoroni’s EnviropHAT packs 4 different sensors, letting you measure temperature, pressure, light level, colour, 3-axis motion, compass heading, and analog inputs. They state that “It's ideal for monitoring conditions in your house, garage or galleon. Set up a web server with Flask and remotely monitor everything from anywhere.”
So, you can use the BMP280 temperature/pressure sensor to measure a drop in temperature, the TCS3472 light and RGB colour sensor to pick up any changes in light and then the LSM303D accelerometer/magnetometer sensor for movement, that book being flown across the room.
1) Setting up the Software
Installation is very simple, boot up your Pi, open the LX Terminal and type:
sudo apt-get update
sudo apt-get upgrade
curl -sS https://get.pimoroni.com/envirophat | bash
This downloads and installs the required software and a number of starter programs and examples to get you started. It also includes an example program folders which you can use to get started with the EnviroPhat.
2) Capturing the Halloween Spectre
The first part of the hack is to create a function to trigger the Pi Camera. I am using a PiNoIR Camera which enables you to capture images in the dark, perfect for spooky Halloween happenings. To capture a good image you can use an InfaRed LED which emits IR which is reflected off of the object and then bounced back into the camera. This means that any Werewolves, clowns or monsters will also be redcap on the camera. I used a LISPAROI, a ring of IR LEDs which slot nicely onto the camera front. You can read more about here. You can buy one from here.
Create a file name as a variable which can be incremented, this is just in case you get more than one picture and saves the original file from being over written. Set up the camera and then trigger the LISPAROI on, take the picture, save it and then turn it off. Update the file name number so that it saves the next image with a different file name.
with picamera.PiCamera() as camera:
camera.capture(file_name + ".jpg")
file_name = int(file_name) + int(1)
file_name = str(file_name)
3) Taking a Temperature Reading
A ghost is said to be present if there is a sudden drop in the temperature of the room. Use the EnviropHAT's sensors to take a temperature reading and then compare it to the previous reading. If there is a drop then trigger the camera, which you set up in the previous step. Take a temperature reading with the code current_temp = weather.temperature().
###establish the temperature of the room###
start_temp = weather.temperature()
print ("The room is ", start_temp)
current_temp = weather.temperature()
print ("Current Temperature is", current_temp)
Later on in the code use a conditional to respond to the change in temperature, not that you are looking for a change in temperature, line 2. For example if the room is already a chilled 12 degrees, (maybe you left the window open) then a significant drop in temp may be down to 7 degrees. Now consider a warm room, say 24 degrees, a noticeable drop would be 18 degrees.
if current_temp - start_temp > 5:
start_temp = current_temp
Who Ya Gonna Call?
4) Checking for Light
If a Ghost does decide to make an appearance then it may give off some light or EMF. Pimoroni keep the code simple and you can take a reading with the line:
amount_of_light = light.light()
This returns the measure of how much light is present in the room, a well light room is around 362 where as a dark room is around 6. Then this value can be used use to check against a particular value, in this program 30. If this occurs then the camera is triggered using the function you set up in step 2
if amount_of_light > 30:
5) Checking for Movement
Again checking for motion or movement is simple and can be set up with the example code from Pimoroni.
readings = readings[-4:]
z = sum(readings) / len(readings)
Then use an IF statement to respond to the motion and trigger the camera to take a picture. The actual EnviropHAT needs to move and this would require the ghost knocking it, but ghost float through objects so it may need to be a monster or beast which knocks the sensor.
if last_z > 0 and abs(z-last_z) > threshold:
last_z = z
We got one!!!
The final part of the hack is to set a small sound notification if the Ghost or Monster triggers the project. Some great ideas from Twitter users what to use, but in the end I settled for the classic Ghost Busters, "We got one!" First install mp3123, in the LX Terminal type: sudo apt-get install mpg321 downloads and installs the required files. Then transfer over an MP3 file to the Pi and use the simple code to stop and start the sound file.
os.system('mpg321 foo.mp3 &')
os.system(‘sudo killall mpg321’)
Download the Code from Github
- Raspberry Pi
- Contact Me
- Hologram Machine