We’ve had some issues at the office with milk going sour, usually over weekends. This long weekend was extra bad as Tuesday morning we had to bin 7 x 4pint bottles of milk that had all turned to nasty smelling cheese over the course of the 3 day weekend.
It was suggested that we put a thermometer in the fridge, sure it’ll work, but it can only show you what the temp is NOW and not over time. Soooo being a geek and very new to the world of Arduino, I knew I had to find a way.
Click here to see Photos of devices used
Enter the ESP8266 12-E and a DHT22 plus ThingSpeak. I found the code I was looking for, thanks very much to “Chispa” over at #GoChispaGo. The code only need a couple of minor tweaks plus a load of translating since his was in Spanish 😀
The code is pretty straightforward (says a guy that really doesn’t have any programming experience with Arduino’s).
Building the project was simple, the ESP8266 is powered by a USB cable and phone charger plugged into the wall and the DHT22 is plugged into 5vdc, ground and pin D4 on the ESP8266 board.
I got it working just fine though so I’m well pleased about that.
The data is logged to a chart: https://thingspeak.com/channels/321768
And the code used is as follows.
#include <DHT.h> #include <ESP8266WiFi.h> // Introducir a continuación tus datos de ThingSpeak y red WiFi String apiKey = "YOUR THINGSPEAK API KEY"; const char* ssid = "your-SSID"; const char* password = "your-PASSWORD"; const char* server = "api.thingspeak.com"; // Time to sleep (in seconds): //const int sleepTimeS = 60; #define DHTPIN D4 #define DHTTYPE DHT22 DHT dht(DHTPIN, DHTTYPE); WiFiClient client; void setup() { Serial.begin(115200); delay(10); dht.begin(); WiFi.begin(ssid, password); Serial.println(); Serial.println(); Serial.print("Connecting to "); Serial.println(ssid); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); Serial.println("WiFi connected"); } void loop() { delay(2000); float h = dht.readHumidity(); float t = dht.readTemperature(); if (isnan(h) || isnan(t)) { Serial.println("DHT sensor reading failure !!!"); return; } if (client.connect(server,80)) { String postStr = apiKey; postStr +="&field1="; postStr += String(t); postStr +="&field2="; postStr += String(h); postStr += "\r\n\r\n"; client.print("POST /update HTTP/1.1\n"); client.print("Host: api.thingspeak.com\n"); client.print("Connection: close\n"); client.print("X-THINGSPEAKAPIKEY: "+apiKey+"\n"); client.print("Content-Type: application/x-www-form-urlencoded\n"); client.print("Content-Length: "); client.print(postStr.length()); client.print("\n\n"); client.print(postStr); Serial.print("Temperature: "); Serial.print(t); Serial.print("*C Humidity: "); Serial.print(h); Serial.print("%"); Serial.println("---->>>> Sent data to ThingSpeak"); } client.stop(); //Sleep // Serial.println("ESP8266 in sleep mode"); // ESP.deepSleep(sleepTimeS * 1000000,WAKE_RF_DEFAULT); Serial.println("Waiting 60 seconds... "); delay(60000); }
Feel free to take the code and play away for your own needs.
![](https://i0.wp.com/www.uk-experience.com/wp-content/uploads/2017/08/d1-mini-20p.jpg?resize=300%2C163&ssl=1)
![](https://i0.wp.com/www.uk-experience.com/wp-content/uploads/2017/08/dht22-20p.jpg?resize=300%2C273&ssl=1)
Check the gasket seal around the door!
Mostly the problem is that the fridge is pretty empty with generally only about 4 or 5 bottles of milk (4 pint each). Fridges really need to be full or they’re not efficient at all.
Comments are closed.