The Haunted Fridge

I guess I’m just obsessed with refrigerator projects. So it goes. For my visualization, I wanted to make a game that used the data collected to control some element of the gameplay. I settled on creating a top down shoot-em-up game that used the data to spawn enemies.

For data collection, I wanted to select something that was not continuous (such as the brightness of my room would have been), so that I could use each instance of it happening as another enemy spawn. I settled on using the refrigerator door because I could also check how long the door was open for and get two data points (when it was opened, and for how long) very easily using just the one sensor.

In my previous fridge project, I had inadvertently encouraged bad energy use habits by more or less rewarding the user for opening up their refrigerator for no reason, so with this one, I wanted there to be something of a punishment for leaving the door open longer than necessary. In my game, the time that the door was left open is used to determine how strong the new enemy is.

The look of the game resulted from the housing I used for the sensor. Wile cleaning out my parents’ house, I found an old Halloween decoration that I liked quite a bit.

The head comes off, so I just used that, cutting a hole in the bottom to allow my sensor to go in there as well as making two small holes in the top to allow the two legs of my photocell to go down into the casing. The photocell itself blends in with the rest of the outside of the devil head very nicely.

The sensor unit is extremely simple, consisting of just the XBee receiver, two AA batteries and the photocell attached to the analog leg of the XBee. The settings of the receiver are pretty much the same as the sleep example from the book, however I set the sample rate to 500 ms and the sleep time to 500ms to allow the unit to be twice as precise with the timing as it would have been with a sample every 1 second. Of course, this means my battery dies twice as fast as well, since the unit needed to wake up each time, but it seemed like a fair trade.

To my surprise, the closed fridge did not impede the signal, and my XBee on the outside was able to comunicate with the devil head in my fridge. I also found that I got about 36 hours out of each pair of batteries.


This greeted me and my girlfriend every time we opened the refrigerator for a few days.

The project uses two Processing sketches: one to log the data and one to play the game. For the data logger, I use a coordinator device plugged into to my computer to receive the values being sent by the receiver. The value from the photocell is checked against a threshold I determined through testing to see if the fridge is dark (meaning the door is closed). If there is a transition from a value bellow the threshold to one above it, the door has been opened, and that time is stored. If there is a transition from above the threshold to bellow, the door has been closed again. The current time is checked against when it was opened, and that data is added to the list of data points along with the time (using the system clock) that the door was first opened.

Periodically, this information is written to a text file, making sure to preserve any readings already in the text file. This allows the computer to be turned off or the processing sketch to be closed without losing data. Of course, no new reading will be made while the sketch is not running.

This seemed to work fairly well, although I did find that a single data point would sometimes be written to the file multiple times for reasons I am unsure of. These had to be manually removed, which was feasible for the few days I ran the sensor, but would obviously not be acceptable if this were a standing unit.

Here’s the sketch
And here is the data I logged.
Every two lines represents an instance of the door opening with the first line showing the date and time, and the second line representing the time in milliseconds that the door was open. Because the sample rate was every 500ms, that is the margin of error in these readings, but for the sake of my game that was just fine.

Speaking of the game, I liked the devil head, and I liked the idea of tying the game to the physical object, so I used it as the enemy in the game. The same devil head that stares you down when you open your fridge will now descend to attack you, which seemed fun. To make it spin, I took a few pictures of it at various angles.

To give the game some pacing, each day of fridge data consists of a single wave of devil heads, which needs to be destroyed before the next wave will arrive. For each wave, the entire day is compressed to a small time. Every time the fridge was opened in this compressed time frame, a new devil appears with its size varying based on the length the door was opened for. When the player shoots them, they shrink slightly, eventually destroying them. Should a devil reach the bottom of the screen, it will reappear at the top, larger and faster than before.

There is also a bar along the side of the screen during waves that indicates when the next enemy will be and how large it will be.

Here’s the sketch for the game.