Spark.io Refridgerator Monitor

A few weeks ago my wife noticed our refrig­er­a­tor tem­per­a­ture was start­ing to go up and down pret­ty dra­mat­i­cal­ly and she was wor­ried about the impact it would have on our food, and her shop­ping bud­get if we had to throw a bunch of stuff out. Luck­i­ly I had a spark device and sen­sors on hand, so I threw togeth­er some hard­ware and code to mea­sure the tem­per­a­ture in the refrig­er­a­tor and the amount of time the door was open.

First, the hard­ware: Spark Mak­er Kit This con­tains every­thing I used in this project. A spark device, the wires, bread­boards, capac­i­tor, temp sen­sor and light sen­sor.

Set­up:
fridge_mon
A pic­ture is worth thou­sands of my hor­ri­ble inef­fi­cient words.
Great instruc­tions on the set up can be found here: Mea­sur­ing the Tem­per­a­ture

I then added the light sen­sor from the kit on A5, using the fil­tered pow­er. After test­ing and such I extend­ed the wires as you will see in the fin­ished prod­uct.

Here is the code for the spark core:

char resultstr[64];
int lightsec;
void setup()
{
pinMode(A7, INPUT); // A7 Analog Input is temperature
pinMode(A5, INPUT); // A5 Analog Input is light
lightsec = 0; // Variable to keep track of how long light is on
Spark.variable("result", &resultstr, STRING);
}
void loop()
{
int temp = analogRead(A7); // Read temp data
int light = analogRead(A5); // Read light data
if (light > 2200) { lightsec++; } // If light is on add a second to count
// Put the results out for Google Script to grab
sprintf(resultstr, "{\"temp\":%d,\"lightsec\":%d}", temp, lightsec);
delay(1000); // wait for a second
}

And here is the code for the Google Script run­ning in the Google Sheet. An exam­ple and instruc­tions can be found here: Log­ging and Graph­ing Data

function collectData() {
var sheet = SpreadsheetApp.getActiveSheet();
var response = UrlFetchApp.fetch("https://api.spark.io/v1/devices/[DEVICE_NAME]/result? access_token=[TOKEN]");
try {
var response = JSON.parse(response.getContentText()); // parse the JSON the Core API created
var result = unescape(response.result); // you'll need to unescape before your parse as JSON
try {
var p = JSON.parse(result); // parse the JSON you created
var d = new Date(); // time stamp
sheet.appendRow([d, p.temp, ((((p.temp*3.3)/4095)-0.5)*100)*1.8+32,p.lightsec]); // Add the line and convert the temp to F
} catch(e)
{
Logger.log("Unable to do second parse");
}
} catch(e)
{
Logger.log("Unable to returned JSON");
}
}

fridge_mon
Final­ly I put the whole con­trap­tion into the refrig­er­a­tor and start­ed mea­sur­ing.

I let it run for about 36 hours, mea­sur­ing every 10 min­utes.

fridge_mon

Here is the data, and it appears the wife might be cor­rect and a 10–15 degree swing is to much for our refrig­er­a­tor.

It also seems we do not go into the fridge much. About 4 mins over 36 hours.

I guess it is time to call the repair man!

Antique Radio Update — 3

Here is the cur­rent work­ing ver­sion of the antique radio. I hooked togeth­er the Net­duino, Spark­fun MP3 Play­er and all of the but­tons, switch­es and lights and placed them in the case.

It is now up and run­ning in the liv­ing room and seems to be oper­at­ing with no issues. At some point in the future I need to put in a real speak­er, with an amp, and replace the poten­tiome­ter to make a work­ing vol­ume knob. But, as with most projects, once it works it sits until I get around to it!

Resources

I believe that is every­thing. My code con­tains some stuff for a vol­ume con­trol, com­ment­ed out, and I am sure there bet­ter ways to do some of it. Any sug­ges­tions are of course wel­come! There are ton of resources online and over­all it was a fun project and I am look­ing for­ward to find­ing anoth­er one soon.

 

Antique Radio Update — 2

I now have the MP3 play­er hooked up to the Net­duino and all of the switch­es appear to be work­ing. The poten­tiome­ter was shot and the rest of them did not func­tion much bet­ter. I will need to look into get­ting replace­ments.

Luck­i­ly I was able to find some code on the Net­duino forums and the heavy lift­ing of get­ting the Net­duino to com­mu­ni­cate with the VS1053b over SPI was already com­plet­ed. They are a great resource, check them out if you have any ques­tions.


Code from the Net­duino Forum for the VS1053b (Thanks hanz­ibal!) I made some tweaks to a few areas for it to work in my project. I will put every­thing in the next and final (for now) post.

Now to try to put every­thing into the case and make it look bet­ter for the liv­ing room.

 

Antique Radio Update — 1

One of the pieces of fur­ni­ture my wife brought with her when she moved in was an old radio / phono­graph play­er that had been gut­ted of pret­ty much all of the work­ing parts. All that was left was the switch­es, old tubes and an ancient speak­er. I thought it would be a good project to try and turn it into a stand­alone mp3 play­er using the old but­tons as the inter­face. So after ask­ing for per­mis­sion, prob­a­bly the most impor­tant step, I pro­ceed­ed to fig­ure out how to make this work.

The first point I should make is I know noth­ing about elec­tron­ics, beyond plug­ging them in and look­ing for burnt parts when they do not work any­more. So I knew this was going to be a learn­ing expe­ri­ence. I decid­ed on the Net­duino ( http://netduino.com/ ) as the prod­uct to try and make this work, which uses C# and Visu­al Stu­dio to devel­op in. I also real­ized the Net­duino would need some­thing to decode mp3’s, so I pur­chased a VS1053b shield from Spark­Fun. ( https://www.sparkfun.com/products/10628 ) In some of the pic­tures or videos you may see a Net­duino Plus ( it has an Eth­er­net port ), I was using both boards to devel­op on and may use the Net­duino Plus in the future if I can fig­ure out how to stream mp3’s to the shield. Both prod­ucts I select­ed have a ton of online sup­port and infor­ma­tion. Luck­i­ly I was able to find infor­ma­tion I was able to under­stand and a lot of peo­ple ask­ing the same ques­tions I had. Also Net­duino and Net­duino Plus have a cou­ple of books you can get with them cov­er­ing all of the basics. They were also very well writ­ten and avail­able on their site.

After tak­ing the con­sole apart I real­ized I had a radio switch with 5 selec­tors, two poten­tiome­ters and a four sec­tion switch. There actu­al­ly may have been more, the radio has two more but­tons, but I think one was to set the sta­tions back in the day and the oth­er was to turn it off (I think). I decid­ed to use the selec­tor to turn the mp3 play­er on when it was switched to phone and the five radio but­tons to switch between gen­res of music. As well as try to use one of the poten­tiome­ters for vol­ume.

My first step was to take the parts out, hook them up and try to get elec­tric­i­ty flow­ing through them to see if they worked. I was sur­prised the radio but­tons worked well, phono­graph switch worked and the poten­tiome­ters seemed to work.

Next to work this all togeth­er with the mp3 play­er shield. I will post some code when I am fin­ished. It is all rather ugly right now.