Milk cooler temperature logger
Build it step by step
0 of 8 doneSet the RTC
Run the RTClib ds3231 example.
Wire the probe and the Uno
As in the table.
Check the probe in ice water
Near 0 degrees.
Upload the sketch
Check the LCD.
Test the alarm with a lower limit
Set LIMIT_C to 20 for a test.
Fit the probe in the tank pocket
Dry, and sealed against water.
Put the electronics in a box
Away from splashes.
Review the SD log after a day
Open milk.csv.
How do you build a milk cooler temperature logger?
A probe in a bulk milk cooler logs temperature every minute to an SD card and sounds a local alarm if milk stays above 4 degrees for 20 minutes. You need Arduino Uno R3, DS18B20 waterproof probe, Resistor 4.7 kΩ, MicroSD Card Module, DS3231 RTC module, 16x2 LCD with I2C backpack (PCF8574), Active buzzer 5 V, Tactile push button 6 mm and Jumper wires male to male (40 pcs, 20 cm). It takes 8 steps and about 150 minutes.
- Level
- Intermediate
- Time
- About 150 min
- Parts
- 9
Wiring
| From | To | Why |
|---|---|---|
| DS18B20 probe red, black, yellow | Uno 5V, GND, D2 with 4.7 k from D2 to 5V | Milk temperature |
| DS3231 SDA and SCL | Uno A4 and A5 | Real-time clock |
| LCD I2C SDA and SCL | Uno A4 and A5 | Display (same I2C bus) |
| DS3231 and LCD VCC and GND | Uno 5V and GND | Power |
| SD module CS, MOSI, MISO, SCK | Uno D10, D11, D12, D13 | Storage |
| SD module VCC and GND | Uno 5V and GND | Power |
| Buzzer plus and minus | Uno D6 and GND | Alarm |
| Silence button | Uno D7 to GND | Internal pull-up |
Code
A stainless steel DS18B20 probe sits in a pocket in the tank wall (never in the milk itself unless it is a food-grade sheathed probe you can clean) and the Uno writes the temperature to an SD card once a minute with the time from the DS3231, giving a record you can review. A short rise, such as when the lid is opened, should not trigger an alarm, so the buzzer only sounds after the milk has stayed above the limit for twenty minutes in a row. A missing or broken probe also raises the alarm, because a silent logger is worse than none. A daily summary line (highest, lowest, minutes above the limit) is written at 8 am. The limit and delay are placed at the top of the sketch: confirm the correct values with your dairy's quality rules before relying on them. This is a helpful logger, not a certified food-safety record or a replacement for the cooler's own controls. This version has a local buzzer and display only; sending an SMS needs a mobile network module and is a good later upgrade. Use the DS18B20's 4.7 k pull-up and keep the cable short. Calibrate the probe in a glass of ice water (it should read near 0 degrees) and note any offset. Setup: Arduino IDE, board "Arduino Uno". Install RTClib, OneWire, DallasTemperature, and LiquidCrystal_I2C.
Runs on a virtual Arduino Uno in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).
#include <SPI.h>
#include <SD.h>
#include <Wire.h>
#include <RTClib.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal_I2C.h>
const uint8_t ONEWIRE_PIN = 2, SD_CS = 10, BUZZER = 6, SILENCE = 7;
const float LIMIT_C = 4.0; // the limit you are checking against, confirm yours
const uint8_t ALARM_AFTER_MIN = 20; // ignore short spikes such as a lid open for a minute
OneWire ow(ONEWIRE_PIN);
DallasTemperature ds(&ow);
RTC_DS3231 rtc;
LiquidCrystal_I2C lcd(0x27, 16, 2); // change 0x27 to 0x3F if the screen stays blank
uint8_t minutesAbove = 0;
bool silenced = false;
float dayMax = -100, dayMin = 100;
uint16_t dayMinAbove = 0;
int lastMinute = -1, lastSummaryDay = -1;
void logLine(const char *tag, float v) {
File f = SD.open("milk.csv", FILE_WRITE);
if (!f) return;
f.print(rtc.now().timestamp());
f.print(',');
f.print(tag);
f.print(',');
f.println(v, 1);
f.close();
}
void setup() {
pinMode(BUZZER, OUTPUT);
pinMode(SILENCE, INPUT_PULLUP);
lcd.init(); lcd.backlight();
ds.begin();
rtc.begin();
SD.begin(SD_CS);
lcd.print("Milk logger");
}
void loop() {
DateTime n = rtc.now();
if (!digitalRead(SILENCE)) silenced = true;
if (n.minute() != lastMinute) { // once a minute
lastMinute = n.minute();
ds.requestTemperatures();
float t = ds.getTempCByIndex(0);
bool bad = (t == DEVICE_DISCONNECTED_C);
lcd.clear();
if (bad) {
lcd.print("PROBE FAULT");
logLine("PROBE_FAULT", 0);
minutesAbove = ALARM_AFTER_MIN; // treat a missing probe as an alarm
} else {
lcd.print("Milk "); lcd.print(t, 1); lcd.print(" C");
logLine("T", t);
if (t > dayMax) dayMax = t;
if (t < dayMin) dayMin = t;
if (t > LIMIT_C) { if (minutesAbove < 255) minutesAbove++; dayMinAbove++; }
else { minutesAbove = 0; silenced = false; }
}
lcd.setCursor(0, 1);
lcd.print(minutesAbove >= ALARM_AFTER_MIN ? "ALARM TOO WARM " : "OK");
if (n.hour() == 8 && n.minute() == 0 && n.day() != lastSummaryDay) { // daily summary at 8 am
lastSummaryDay = n.day();
logLine("DAY_MAX", dayMax);
logLine("DAY_MIN", dayMin);
logLine("MIN_ABOVE_LIMIT", dayMinAbove);
dayMax = -100; dayMin = 100; dayMinAbove = 0;
}
}
if (minutesAbove >= ALARM_AFTER_MIN && !silenced) {
digitalWrite(BUZZER, (millis() / 500) % 2); // beep until silenced or cooled
} else {
digitalWrite(BUZZER, LOW);
}
}Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Probe in ice water | About 0 degrees on the LCD |
| Probe in warm water, with LIMIT_C set to 20 and ALARM_AFTER_MIN set to 2 | Alarm starts after two minutes |
| Press the silence button | Buzzer stops until it cools |
| Unplug the probe | PROBE FAULT and alarm |
| Read the SD card | One row per minute |
If it does not work
LCD blank
Try address 0x3F, or turn the contrast screw.
Reads -127
Probe not connected or the pull-up resistor missing.
No SD rows
Format FAT32 and check CS on D10.
Wrong time
RTC not set, or the coin cell is flat.
Alarm too sensitive
Raise ALARM_AFTER_MIN.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the milk cooler temperature logger?
Arduino Uno R3, DS18B20 waterproof probe, Resistor 4.7 kΩ, MicroSD Card Module, DS3231 RTC module, 16x2 LCD with I2C backpack (PCF8574), Active buzzer 5 V, Tactile push button 6 mm and Jumper wires male to male (40 pcs, 20 cm).
How long does the milk cooler temperature logger take to build?
About 150 minutes for a intermediate maker, in 8 steps.
How do I know the milk cooler temperature logger works?
Probe in ice water: About 0 degrees on the LCD. Probe in warm water, with LIMIT_C set to 20 and ALARM_AFTER_MIN set to 2: Alarm starts after two minutes. Press the silence button: Buzzer stops until it cools.
LCD blank: what should I check?
Try address 0x3F, or turn the contrast screw.
Reads -127: what should I check?
Probe not connected or the pull-up resistor missing.
No SD rows: what should I check?
Format FAT32 and check CS on D10.
Wrong time: what should I check?
RTC not set, or the coin cell is flat.
