Home IoT Hub Series · 05
[Part 5] Is the fridge really cooling? DS18B20 fridge temperature watch
Place a waterproof DS18B20 probe inside the fridge and send the temperature to the hub.
This part adds the first cold-storage node. Put a waterproof DS18B20 probe inside the refrigerator, keep the Wemos board outside, and send the measured value to slot 12.
The important point is placement: only the metal probe goes into the fridge. Keep the board, USB cable, and power source outside so condensation does not reach the electronics.
![[Part 5] Is the fridge really cooling? DS18B20 fridge temperature watch hero image](/iot-lab/assets/fridge-temperature-ds18b20-hero.png)
This article is part of the Home IoT Hub system connected to the central NodeMCU server built in Part 2: Building the Brain. A waterproof DS18B20 probe reports the fridge temperature so the hub can detect storage and cooling problems. The collected data is sent over the local
IoT_Hub_Net network and updates slot 12 for fridge temperature on the central server (/set?no12=value), becoming part of the decision pipeline for the 20-channel smart-home controller.Parts and cost
| Part | Qty | Unit price | Note |
|---|---|---|---|
| Wemos D1 Mini (ESP8266) | 1 pc | $1.50 | Sensor node body |
| DS18B20 waterproof type | 1 pc | $1.50 | stainless probe, 1 m cable |
| 4.7kΩ resistor | 1 pc | $0.10 | for pull-up |
| Jumper wires | 3 pc | — | |
| Micro USB cable + charger | 1 set | — | |
| Total | $3 |
Pin wiring
| Sensor / module | Board pin |
|---|---|
| Red (VCC) | 3.3V |
| Black (GND) | GND |
| Yellow (DATA) | D1 (GPIO5) |
Full code
#include <ESP8266WiFi.h> #include <ESP8266HTTPClient.h> #include <OneWire.h> #include <DallasTemperature.h> const char* ssid = "IoT_Hub_Net"; const char* password = "iothub1234"; const char* hubURL = "http://192.168.1.1"; #define ONE_WIRE_BUS 5 // D1 (GPIO5) #define SLOT_NO 12 // brain 12note= Fridge Temp #define INTERVAL 30000 // 30-second interval OneWire oneWire(ONE_WIRE_BUS); DallasTemperature sensors(&oneWire); void setup() { Serial.begin(115200); sensors.begin(); WiFi.mode(WIFI_STA); WiFi.begin(ssid, password); Serial.print("Connecting to IoT_Hub_Net"); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println("\nConnected! IP: " + WiFi.localIP().toString()); } void loop() { sensors.requestTemperatures(); float temp = sensors.getTempCByIndex(0); if (temp == DEVICE_DISCONNECTED_C || temp < -50 || temp > 50) { Serial.println("Sensor read error, retrying..."); delay(2000); return; } Serial.print("Fridge: "); Serial.print(temp); Serial.println(" C"); WiFiClient client; HTTPClient http; String url = String(hubURL) + "/set?no" + String(SLOT_NO) + "=" + String(temp); http.begin(client, url); int code = http.GET(); http.end(); Serial.print("HTTP "); Serial.print(code); Serial.print(" -> "); Serial.println(url); Serial.println(); delay(INTERVAL); }
Upload and check
Connect the Wemos D1 Mini to the PC with a USB data cable, select the ESP8266 board and port in the Arduino IDE, upload the sketch, then open Tools → Serial Monitor and set the baud rate to 115200.
Serial Monitor
After uploading, open Tools → Serial Monitor in the Arduino IDE and set the baud rate to 115200. The following is an example Serial Monitor flow for checking normal operation. This is not a real screenshot. It is an example of the normal output for sending refrigerator temperature to slot 12.
[BOOT] Home IoT Node #05 - Fridge temperature [WIFI] connected to IoT_Hub_Net, ip=192.168.1.52 [1-WIRE] DS18B20 found, parasite_power=OFF [SENSOR] fridge_temp=3.8C [HTTP] GET /set?no12=3.8 [HUB] 200 OK - slot no12 updated [CHECK] gasket cable route OK, next sample in 60000 ms
- If
Connectedorconnectedappears, the Wi-Fi step passed. - If
HTTP 200or200 OKappears, the value reached the brain server. - If the value does not update, check both the slot number in the URL and the sensor wiring.
Build notes
- After upload, open the serial monitor and confirm the fridge temperature is printed. Then check that the hub page shows the same value on the Fridge Temp slot.
- Power on the hub brain first so the node can join
IoT_Hub_Net. - Use the same slot number written in the source code.
- Open the serial monitor at 115200 baud and confirm
HTTP 200. - If the value does not appear on the hub, recheck wiring, GPIO number, and Wi-Fi connection.
Monitoring Fridge Temperature (Waterproof DS18B20)
A fridge seems to hum along steadily, but its internal temperature actually swings every time the door opens. Wiring a waterproof DS18B20 sensor into your Home IoT Hub lets you watch those swings in real time and act before food spoils.
Troubleshooting checkpoints
The node code can look short, but real home installation is affected by placement, power, Wi-Fi quality, and sensor noise. Check these points before letting the node become a decision input for the brain server.
| Symptom | Likely cause | Field fix |
|---|---|---|
| The fridge door does not seal well | The sensor cable lifts the rubber gasket and leaks cold air | Avoid the front gasket, route a thin cable through the hinge-side gap, and use a paper-pull test to verify the seal. |
| Temperature reacts too slowly | The probe floats in still air or touches plastic walls with high thermal lag | Hang the probe in the rear airflow and base alerts on a 5-10 minute moving average instead of one sample. |
| The reading is -127°C or 85°C | DS18B20 communication failed or the first power-up default value is being used | Check the 4.7kΩ pull-up and common GND, and discard the first sample after boot. |
| Wi-Fi is weak near the fridge | The metal body and compressor area block radio signals | Keep the D1 Mini outside on top or beside the fridge, and route only the probe into the cabinet. |
Use Cases
- Setpoint monitoring: Get alerted when the fridge exceeds 5C or the freezer rises above -15C, catching temperature excursions before you'd ever notice by eye.
- Door-ajar and power-outage alerts: A rapid rise over a short span signals a door left open or a power cut. You'll know on your phone even while away.
- Food safety: After a long summer outage, the temperature history gives you evidence for the 'is this still safe to eat' decision. If the fridge stayed above 5C for more than 2 hours, discard perishables to be safe.
- Kimchi fridge: Fermentation temperature drives flavor, so tracking whether ripening mode (about -1 to 0C) and storage mode hold steady helps you manage taste.
Where to Place It
- Center shelf of the fridge: The door side swings 3-5C on every opening, so the inner center is most representative of the average temperature.
- Door pocket: Conversely, mount here to watch the most vulnerable spot, where milk and eggs and other sensitive items sit.
- Freezer: DS18B20 works fine at -18C (rated to -55C), but the cable jacket stiffens in the cold and resists repeated bending, so route it with slack.
- Probe tip position: The metal probe tip is the actual measuring point. Don't press it against a wall; place it in air or next to food at a representative spot.
Practical Tips and Cautions
- Response lag: The waterproof housing makes thermal response slow, tens of seconds to a minute. Read it as a trend, not an instantaneous value.
- Door-gap wiring: Routing the cable through the gasket is convenient, but crushing it breaks the seal, causing frost and higher power bills. Use a flat ribbon cable or route it near the hinge where compression is least. Periodically check that repeated closings haven't worn through the jacket.
- Multiple sensors: OneWire lets you hang several sensors in parallel on one pin, so you can watch fridge, freezer, and kimchi fridge each with its own sensor, distinguished by ROM ID.
- Reference temperatures: 0-5C for refrigeration and -18C or below for freezing are the food-storage standards. Set your alert thresholds to this range.
FAQ
Q. Won't the cable stop the door from closing?
A thin ribbon cable (about 1mm or less) is absorbed by most gaskets. Still, route it near the hinge so pressure isn't concentrated at one point.
Q. Is freezer frost on the sensor a problem?
The waterproof body handles frost and condensation fine. But thick ice slows heat transfer and makes readings more sluggish, so defrost periodically.
Q. My readings run a bit higher or lower than my thermometer.
That's airflow at the sensor spot plus response lag. Compare against a separate thermometer and add a software offset to calibrate.
This article is part of the 20-channel Home IoT system built from the Part 2 central brain server and the distributed edge nodes in Parts 3-19. Use this map to check the slot and sensor flow across the series.
[Part 1] Home IoT Hub overview[Part 2] Central brain server · slots 1-20[Part 3] Stop guessing room comfort · slots 1/2[Part 4] Did I close the door? · slots 9[Part 5] Is the fridge really cooling? · slots 12[Part 6] Should I open the window? · slots 3[Part 7] Stop bathroom mold before it starts · slots 19[Part 8] Is the boiler actually running? · slots 5/17[Part 9] Did I leave the gas stove on? · slots 6[Part 10] Get warned before gas smell becomes obvious · slots 7[Part 11] Catch flame signs while away from home · slots 8[Part 12] Is bad air making you foggy? · slots 13/14[Part 13] Why is the power bill so high? · slots 15[Part 14] Is water leaking, and how much are we using? · slots 16[Part 15] Do not leave windows open in the rain · slots 18[Part 16] Are the lights off and the door locked? · slots 11/10[Part 17] Control the air conditioner from the IoT hub · slots 4[Part 18] Is the dog bowl empty? · slots 20[Part 19] Cool the room only when someone is there · slots 1/4[Part 20] The house finally fits on one screen · slots all