Cold-chain temperature logger

A battery logger with display and alerts for fridges, freezers and cold storage, keeps recording through blackouts.

Safety Board: ESP32-C3 SuperMini Level: ●●○ ⏱ 1–2 h

⚠ Caution

Batteries: watch polarity, use protected cells and a charger with protection, never charge damaged cells unattended.

When the temperature log is the product

Unlike a simple alarm, this logger keeps a record: when a fridge for medicines or food stayed within range and when it did not. That is useful for a shop, a clinic room or a dacha cellar. A small battery keeps it recording through a blackout.

Making the record trustworthy

Store each reading with a timestamp in the flash file system, and export it as CSV. Between samples go to deep sleep, with a sample interval of one to five minutes. After a sleep the clock must stay right, so synchronise with NTP when Wi-Fi is available. The DS18B20 is specified to about ±0.5 °C, and you can check each probe in ice water, which should read close to 0 °C.

  • The screen shows the minimum and maximum since the last reset, as on a professional thermometer.
  • For medicines the typical range is 2 to 8 °C; set the alarm limits to your own requirements.
  • Keep the log when the network is gone. Upload when it returns.

Components

  • ESP32-C3 SuperMini
  • DS18B20 waterproof probe
  • OLED 0.96" 128x64 I2C SSD1306
  • 18650 Li-ion cell + holder
  • TP4056 USB-C Li-ion charger with protection

Wiring

Module Module pin ESP32 pin Note
DS18B20 DATA 1-Wire GPIO5 4.7 kΩ pull-up to 3V3
OLED SDA / SCL I2C GPIO8 / GPIO9 0x3C
Battery 3.7 V Li-ion TP4056 charger, battery to the 5V pin of the board use a protected cell; a boost or the 3V3 pin variant needs a low-dropout setup

Libraries

  • OneWire
  • DallasTemperature
  • Adafruit SSD1306
  • Adafruit GFX Library

Code

#include <WiFi.h>

const char* WIFI_SSID = "YOUR_WIFI";
const char* WIFI_PASS = "YOUR_PASSWORD";

bool connectWiFi(uint32_t timeoutMs = 20000) {
  WiFi.mode(WIFI_STA);
  WiFi.begin(WIFI_SSID, WIFI_PASS);
  uint32_t t0 = millis();
  while (WiFi.status() != WL_CONNECTED && millis() - t0 < timeoutMs) {
    delay(250);
    Serial.print(".");
  }
  Serial.println();
  if (WiFi.status() == WL_CONNECTED) {
    Serial.print("IP: ");
    Serial.println(WiFi.localIP());
    return true;
  }
  return false;
}
#include <WiFiClientSecure.h>
#include <HTTPClient.h>

const char* TG_TOKEN = "123456:ABC-YOUR-BOT-TOKEN";   // from @BotFather
const char* TG_CHAT  = "YOUR_CHAT_ID";

// Keep the text free of double quotes and line breaks (it is inserted into JSON).
bool telegramSend(const String& text) {
  if (WiFi.status() != WL_CONNECTED) return false;
  WiFiClientSecure client;
  client.setInsecure();   // simple; pin the certificate for production
  HTTPClient http;
  String url = String("https://api.telegram.org/bot") + TG_TOKEN + "/sendMessage";
  if (!http.begin(client, url)) return false;
  http.addHeader("Content-Type", "application/json");
  String body = String("{"chat_id":"") + TG_CHAT + "","text":"" + text + ""}";
  int code = http.POST(body);
  http.end();
  return code == 200;
}
#include <Wire.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

OneWire ow(5); DallasTemperature ds(&ow);
Adafruit_SSD1306 oled(128, 64, &Wire, -1);
const float LIMIT_HIGH = -10.0;             // freezer: -10; use 8.0 for a fridge
const uint64_t SLEEP_US = 5ULL * 60ULL * 1000000ULL;
RTC_DATA_ATTR float tMin = 99, tMax = -99; RTC_DATA_ATTR int wakeCount = 0; RTC_DATA_ATTR int alertSent = 0;

void setup() {
  Serial.begin(115200); Wire.begin(8, 9); ds.begin(); ds.requestTemperatures();
  float t = ds.getTempCByIndex(0); wakeCount++;
  if (t > -100) { tMin = min(tMin, t); tMax = max(tMax, t); }
  oled.begin(SSD1306_SWITCHCAPVCC, 0x3C); oled.clearDisplay(); oled.setTextColor(WHITE);
  oled.setTextSize(2); oled.setCursor(0, 0); oled.printf("%.1f C", t);
  oled.setTextSize(1); oled.setCursor(0, 28); oled.printf("min %.1f  max %.1f", tMin, tMax); oled.setCursor(0, 40); oled.printf("wake #%d", wakeCount); oled.display();
  bool bad = t > LIMIT_HIGH || t < -100;
  if (bad && alertSent < 3 && connectWiFi()) { telegramSend(String("Cold chain alert: ") + (t < -100 ? "sensor fault" : String(t, 1) + " C")); alertSent++; }
  if (!bad) alertSent = 0;
  if (wakeCount % 144 == 0 && connectWiFi()) telegramSend(String("Logger alive. Last 12 h min/max: ") + String(tMin, 1) + " / " + String(tMax, 1));
  delay(3000); oled.ssd1306_command(SSD1306_DISPLAYOFF);
  esp_sleep_enable_timer_wakeup(SLEEP_US); esp_deep_sleep_start();
}
void loop() {}

Build tips

  • Place the probe in a bottle of water or glycol to avoid false alarms when the door opens.
  • The OLED is only on briefly each wake to save the battery.

What you need

Buy the parts kit · Estimated total: $11.30

ESP32-C3 SuperMini × 1
$2.50
Buy at AliExpress Buy at Amazon.com
DS18B20 waterproof probe × 1
$1.50
Buy at AliExpress Buy at Amazon.com
OLED 0.96" 128x64 I2C SSD1306 × 1
$2.50
Buy at AliExpress Buy at Amazon.com
18650 Li-ion cell + holder × 1
$4.00
Buy at AliExpress Buy at Amazon.com
TP4056 USB-C Li-ion charger with protection × 1
$0.80
Buy at AliExpress Buy at Amazon.com
🇺🇦 Ukraine🌍 Other countries

Other countries: order these parts on AliExpress with the links below.

Some links are affiliate links: we may earn a commission at no extra cost to you.

Related ideas

⚠ Caution

Batteries: watch polarity, use protected cells and a charger with protection, never charge damaged cells unattended.

Orchard and greenhouse frost alert

A battery sensor that wakes up rarely and sends an alert when the temperature falls toward freezing.

  • Board ESP32-C3 SuperMini
  • Level ●○○ Beginner
  • Build time 1–2 h
Pick parts / kit
⛔ High risk

Mains 220–230 V can kill. Work with the power off, use certified isolated modules in an enclosure, fuse the line, and ask a qualified electrician if you are not sure.

Power outage notifier

A battery-backed ESP32-C3 that detects when mains disappears and sends a message with the time of the blackout.

  • Board ESP32-C3 SuperMini
  • Level ●●○ Intermediate
  • Build time 2–3 h
Pick parts / kit
⚠ Caution

Batteries: watch polarity, use protected cells and a charger with protection, never charge damaged cells unattended.

BLE temperature beacon

An ESP32-C3 on a Li-ion cell that advertises temperature over BLE and lasts months on deep sleep.

  • Board ESP32-C3 SuperMini
  • Level ●●○ Intermediate
  • Build time 1–2 h
Pick parts / kit

← All module ideas →

Comments

No comments yet. Share your experience or ask a question.

Comments are moderated.