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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
#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.

ESP8266 next to 20p

DHT22 sensor next to 20p