Automatic dusk-to-dawn light
Lights switch on by themselves at dusk and off again in the morning.
Shop by category
Shop all componentsA waterproof DS18B20 probe measures the water temperature. The ESP32 switches a relay on when the water falls below the low limit and off above the high limit, a gap called hysteresis that stops the relay chattering. The OLED shows the temperature and heater state. This is a hobby controller: a fish-keeping heater should keep its own built-in thermostat, and this project should only ever be a second, independent safety.
Anything connected to 230 V mains must be installed by a qualified electrician in a closed, earthed enclosure. Test with a low-voltage lamp first.
Mains power near water is a shock risk. Use an RCD-protected socket and keep all electronics out of splash range.
Tick anything you already have and the total updates.
Waterproof DS18B20 temperature probe
Follow the colours: red is power, dark grey is ground, blue is a signal.
USB phone charger. Anything connected to 230 V mains must be installed by a qualified electrician in a closed, earthed enclosure. Test with a low-voltage lamp first.
aquarium_thermostat.inoVerify & upload in Electrolark#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>
#include <Adafruit_SSD1306.h>
OneWire ow(4);
DallasTemperature probe(&ow);
Adafruit_SSD1306 oled(128, 64, &Wire, -1);
const int RELAY_PIN = 26;
const bool ACTIVE_LOW = true;
const float LOW_C = 25.0, HIGH_C = 26.0;
bool heater = false;
void setHeater(bool on) { heater = on; digitalWrite(RELAY_PIN, (on == ACTIVE_LOW) ? LOW : HIGH); }
void setup() {
pinMode(RELAY_PIN, OUTPUT);
setHeater(false);
probe.begin();
Wire.begin(21, 22);
oled.begin(SSD1306_SWITCHCAPVCC, 0x3C);
}
void loop() {
probe.requestTemperatures();
float t = probe.getTempCByIndex(0);
if (t == DEVICE_DISCONNECTED_C) {
setHeater(false); // fail safe: heater off if the probe is lost
} else if (t < LOW_C) {
setHeater(true);
} else if (t > HIGH_C) {
setHeater(false);
}
oled.clearDisplay(); oled.setTextColor(WHITE);
oled.setTextSize(3); oled.setCursor(0, 8); oled.print(t, 1); oled.print("C");
oled.setTextSize(1); oled.setCursor(0, 50); oled.print(heater ? "Heater ON" : "Heater off");
oled.display();
delay(2000);
}
The probe is not detected. Check the pull-up resistor and wiring.
The gap between LOW_C and HIGH_C is too small.
Check ACTIVE_LOW and the relay wiring.
A heater that stays on with no feedback can overheat the tank.
No. Use it as an extra control, not the only safety.
The stainless steel probe is waterproof. The cable joint should stay out of the water.
7 parts: ESP32-WROOM-32 38-Pin Development Board, DS18B20 Waterproof Temperature Probe – 1m Cable, Stainless Steel, 5V Relay Module with Optocoupler, 0.96" OLED Display 128x64, Resistor Assortment Kit (30 Values), Solderless Breadboard and Dupont Jumper Wires (40 pcs). On this page you can tick the parts you already have and add only the rest to your cart.
It is a intermediate project and takes about 1.5 hours. The build on this page has 6 steps.
No. This page has the complete, tested code (aquarium_thermostat.ino).
About ₹752 for the parts at the prices on this page. Quantity price breaks lower the cost when you build several.
Reading a DS18B20 with OneWire; Hysteresis control; Why a backup thermostat matters.
Ideas that reuse this build: ESP32 multi-probe fridge logger. They are listed under Take it further on this page.
Lights switch on by themselves at dusk and off again in the morning.
A precise thermostat that keeps tropical fish at a steady 25–26 °C.
Starts the pump when the tank runs low and stops it when it is full.
Tap a hidden pad to switch a lamp on or off, even through a wooden desk.
Learning project. Check every circuit and the datasheet of each part before you power it up.