Battery cold-chain logger with display

Logs min/max temperature every 5 minutes in deep sleep, shows it on a small OLED and sends alerts through Telegram.

Level: Intermediate Board: ESP32-C3 SuperMini Safety & alarms

⚠ Safety

Li-ion cells: watch polarity, use protected cells and a charger with protection, never leave a damaged cell charging unattended.

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

Ukraine: we buy and sell these parts ourselves, order them on this site.

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

Wiring

ModuleModule pinESP32 pinNote
DS18B20 DATA1-WireGPIO54.7 kΩ pull-up to 3V3
OLED SDA / SCLI2CGPIO8 / GPIO90x3C
Battery3.7 V Li-ionTP4056 charger, battery to the 5V pin of the boarduse a protected cell; a boost or the 3V3 pin variant needs a low-dropout setup

Libraries

Arduino IDE → Tools → Manage Libraries, then install:

  • OneWire
  • DallasTemperature
  • Adafruit SSD1306
  • Adafruit GFX Library

Code

cold-logger.ino
#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() {}

Flash a ready firmware from the browser Paste your error into the AI Error Doctor

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.

← ← All projects

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

Comments

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

Comments are moderated.