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
System architecture and data pipeline note
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

PartQtyUnit priceNote
Wemos D1 Mini (ESP8266)1 pc$1.50Sensor node body
DS18B20 waterproof type1 pc$1.50stainless probe, 1 m cable
4.7kΩ resistor1 pc$0.10for pull-up
Jumper wires3 pc
Micro USB cable + charger1 set
Total$3

Pin wiring

[Part 5] Is the fridge really cooling? DS18B20 fridge temperature watch wiring diagram
Sensor / moduleBoard pin
Red (VCC)3.3V
Black (GND)GND
Yellow (DATA)D1 (GPIO5)

Full code

[Part 5] Is the fridge really cooling? DS18B20 fridge temperature watch - Code 2
#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 Connected or connected appears, the Wi-Fi step passed.
  • If HTTP 200 or 200 OK appears, 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.

SymptomLikely causeField fix
The fridge door does not seal wellThe sensor cable lifts the rubber gasket and leaks cold airAvoid 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 slowlyThe probe floats in still air or touches plastic walls with high thermal lagHang 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°CDS18B20 communication failed or the first power-up default value is being usedCheck the 4.7kΩ pull-up and common GND, and discard the first sample after boot.
Wi-Fi is weak near the fridgeThe metal body and compressor area block radio signalsKeep 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.