I have a problem, I’m trying to lose weight but I love snacking late at night. And no one knows that I even do it. That being one of my biggest hurdles, I figured why not include all my social media friends and followers in helping me. Whether they know it or not.
So I decided to hook up my fridge to the internet, with an arduino and wishield and have it post to facebook and twitter whenever I try and get myself a late night snack.
I even have a tumblr account setup to track my progress and see what else is being done with it.
This instructable is for a lite version of it. The message is hard coded in the php file, and so is the set times it will activate. The one I have personally is also updating and running off a MySQL database for some extra tracking for opening and closing, also so I can also give the fridge a wider array of things to say if I open the fridge contained in a database as well. But what I posted will do what it says, post a message to FB and TW if you try to sneak a late night snack.
If anything doesn’t seem to be working properly, let me know. I did take my version and clean it up best I could for everyone and simplify it as a starting point.
Step 1: Hardware Components
The setup of the fridge needed these parts:
Wall wart to power Arduino with Center-positive 5.5×2.1mm barrel connector
Force Sensative Resistor
10K ohm resistor
1 or 2, those kinda squishy cabinet door bumber things that make them not sound like there getting slammed hard.
Breadboard (options, but very useful also a zip tie can be handy)
A web server running PHP. (You cannot trigger the facebook and twitter apps without it being on a live server (at least it wouldn’t work when I tried it).
Step 2: Wiring the Arduino
A great place to start learning how to use the pressure resistor with an arduino is http://www.ladyada.net/learn/sensors/fsr.html#simple_demonstration_of_use
I started with the simple demo to start it off.
The final setup I did has one leg of the pressure resistor hooked into 5V
The other leg has the 10K resistor wire to ground for pull down and the end is plugged into Analog 0.
This reads in the value of the pressure resistor.
And since I didn’t want to have to wire it directly to my computer and have wires all over my house I used a WiShield from asynclabs.
You can use any method to do the communication: wifi, wired, bluetooth. I just happened to have a WiShield around to use.
The WiShield let you still plug the pressure resistor and other wires needed to still interface with the arduino.
The picture included is for reference, just plug in things the same with the WiShield attached to the arduino.
I have an outlet in one of the cabinets near my fridge, so that turned out to be a great spot to put it. It is tucked away and out of sight. I got a 12V 500mA wall wart from radio shack and a Center-positive 5.5×2.1mm barrel connector, as advised from a quick google search.
Step 3: Arduino Code
The code is built with “SimpleClient” as a starting point from asynclabs’ code.
First I’ll show you all the code and then break it down.
(I replaced all my router’s important info with XXXXXXs, just fyi)
* A simple sketch that uses WiServer to serve a web page
int fsrAnalogPin = 0; // FSR is connected to analog 0
int fsrReading; // the analog reading from the FSR resistor divider
boolean hasOpened = false;
boolean hasClosed = false;
boolean isOpen = false;
#define WIRELESS_MODE_INFRA 1
#define WIRELESS_MODE_ADHOC 2