Last summer our San Francisco studio realized it had a problem. Our fussy upstairs refrigerator wouldn't latch every time it was closed.
Sometimes it would sit that way for hours until someone discovered it was open. Forlorn and alone our fridge would rest, using up all the unicorn tears and panda fur oil, spoiling our lunches, and generally not rocking out to hit 80s music.
A fridge that doesn't close is hardly a fridge at all, more like an extremely inefficient air conditioner, but we knew we had the design mojo to tackle this serious problem. Using Arduino we built an alarm that would go off if the fridge had been left open too long, notifying people to come arunnin' to give it a good ol' heave shut. This week we're celebrating the six-month anniversary of our fridge alarm, and we wanted to take a moment to share it with you.
The alarm uses a hall effect sensor and a neodymium magnet to sense when the refrigerator door is opened, at which point the Arduino starts counting down. If the door is open for more than a minute the alarm sounds, filling the studio with smash 80s hits until the situation is addressed.
Building your own.
If you're interested in building your own fridge alarm, you're going to need a few things:
Arduino Uno - This is the brains of the whole system. We used an Arduino Duemilanove, but the Uno is the latest-and-greatest.
Hall Effect Sensor - These little guys sense a magnetic field, making them great for non-contact switches. There's a lot of variety in hall effect sensors, but you'll want one that's non-latching and omnipolar. The one currently available on SparkFun is latching, which is not what you want, but a number of people have had success with this one at Mouser. Be sure to check the datasheet to make sure you're hooking up the pins correctly, as the diagram displayed below is specific to the hall effect sensor I used. For extra credit you could use a magnasphere switch, which are truly awesome but kinda pricy.
Magnet - The stronger the magnet, the further away from the hall effect sensor it can be placed. Fridge magnets tend to be too weak, so we're using a 3/8” disc-shaped neodymium magnet.
Arduino ProtoShield - You'll want to prototype your alarm and get your code and circuits solid before actually hooking it up to your fridge. While a ProtoShield isn't absolutely necessary, it makes the process of breadboarding your circuits far more convenient. A breadboard and a fistful of wires will get the same job done.
You're also likely going to need tape, wires, an LED for testing, a USB cable for uploading sketches to your Arduino, longer wires for permanently installing your alarm, and a power adapter so your Arduino can run without being plugged into a computer. Not to mention a problematic fridge.
Phew! Does that seem like a lot to think about? If you're just getting started with Arduino you might want to consider a starter kit and Massimo Banzi's introductory book. Get your sea legs under you, and then move on to the harder stuff.
Wiring it up.
The circuitry for the fridge alarm is fairly basic, but to make things easy I've sketched up the wiring in Fritzing, an open-source electronics diagramming tool. Please note that this diagram refers specifically to the pin arrangement on my hall effect sensor, which may be different than the one you are using. Indeed, my sensor was scrounged from my father's basement workshop, and its packaging suggests it was purchased from Radio Shack in the early 1980s. Your mileage may vary!
Here's a zip file containing the Arduino code we used for our fridge alarm. It requires two third-party Arduino libraries, Bounce and Tone, which are included in the zip file but can also be downloaded from their respective pages. If you've never installed a third-party library before, the Arduino website has you covered.
Our fridge alarm code is fairly well-documented so you should be able to tweak it as necessary, shortening the alarm delay for testing purposes. To test your code, move your magnet in range of the hall effect sensor. Then move it away, to simulate the fridge door opening. The testing LED should light, and after the specified delay the alarm should go off. There are also options within the code to make the buzzer chirp every time the door closes or opens (or, technically, every time the magnet moves in and out of range of the hall effect sensor), or to mute the buzzer entirely and simply blink the LED when the alarm goes off.
Finally, by far the coolest part of the fridge alarm is that it plays the hottest RTTTL charts through a piezoelectric buzzer. We're pretty fond of the song that's already on there, but there are certainly options to suit anyone's musical tastes. MeRWiN's Ringtone Search is an awesome (vintage!) resource for ringtones, that will stab you in the face less than most other ringtone websites.
Download the code, wire up your Arduino by referring to the included diagram, upload the sketch to your Arduino, and test it!
Thanks for celebrating with us, and let us know if you build your own!