Build a Reef Aquarium Controller with ESP32: Dosing Pumps, Auto Top-Off, and Lighting Schedules
ESP32 DevKit Board
Optical Liquid Level Sensors (x2 for ATO redundancy)
12V Peristaltic Dosing Pumps (x4, ATO + 3 dosing channels)
Relay Module for Pump Switching
Waterproof Temperature Probe
Float Switch for Reservoir Monitoring
0-10V LED Dimming Driver
IP65 Enclosure for Controller Electronics
Drip Tray / Spill Containment Basin
Prices and availability as of Nov 22, 5:36 AM ET and subject to change. The price shown on Amazon at the time of purchase applies.
A reef aquarium is a far less forgiving automation target than the hydroponic and garden-irrigation projects makers usually reach for — a saltwater reef tank's chemistry (calcium, alkalinity, magnesium) has to stay within a tight band for coral to survive, salt water is brutal on electronics and connectors, and a top-off pump that sticks "on" overnight can crash salinity and kill a tank in hours. This project builds an ESP32-based reef controller that handles automated dosing, auto top-off (ATO) with real fail-safes, and lighting schedules, with the sensor and plumbing details that make the difference between a controller that helps and one that eventually floods your stand.
Difficulty and What to Expect
This is an intermediate-to-advanced project, less for the electronics (which are fairly standard ESP32 relay and pump control) than for the fail-safe plumbing and sensor placement that keep a mistake from becoming a dead tank. Budget a weekend for the controller build and a second weekend for careful in-tank testing with fail-safes deliberately triggered before you trust it unattended.
What the Controller Actually Does
| Subsystem | Hardware | Function |
|---|---|---|
| Auto top-off (ATO) | Dual optical or float sensors + peristaltic pump | Replaces evaporated fresh water to hold salinity steady |
| Dosing (Ca/Alk/Mg) | 3x peristaltic dosing pumps | Scheduled small doses to hold reef chemistry stable |
| Lighting | 0-10V or PWM dimming interface to LED fixture | Sunrise/sunset ramping and photoperiod scheduling |
| Monitoring | Temperature probe, optional pH probe | Logging and threshold alerts |
Auto Top-Off: Where Most DIY Builds Fail
A single-sensor ATO is a known failure mode in the reef-keeping world for good reason: if that one optical sensor gets a salt-creep film or a bubble stuck on it and reads "low" continuously, the pump runs until your freshwater reservoir is empty into the tank, or worse, until the reservoir itself is empty and the pump runs dry — or the sensor fails the other way and never tops off at all. Build this with redundancy, not just as a feature, but as the actual design basis:
- Use two independent sensors — a primary and a backup mounted slightly lower — and only allow the pump to run when the primary calls for water; if the backup also reads low after a set primary runtime, that's normal, but if the backup is the one calling for water while the primary says it's fine, flag a fault instead of continuing to dose.
- Enforce a hard maximum pump runtime per top-off cycle in firmware (a few seconds, calibrated to your reservoir and tank size) — the pump should never be allowed to run continuously for more than that window, full stop, regardless of what the sensors say.
- Monitor reservoir level separately if you can (even a simple float switch in the freshwater jug) so a reservoir running dry triggers an alert rather than the pump just running dry silently.
- Always route your ATO reservoir and dosing containers so a full, uncontrolled spill lands in a basin or drip tray, not directly on the floor or into cabinetry — the controller is a second line of defense, not the only one.
Dosing Pumps and Chemistry Stability
Peristaltic dosing pumps (the same type used in hobby-grade commercial dosers) driven by the ESP32 through simple relay or MOSFET switching handle calcium, alkalinity, and magnesium supplements on a scheduled, small-and-frequent basis — several small doses spread through the day hold chemistry far more stable than one large daily dose, which causes swings corals respond to poorly. Calibrate each pump's actual mL-per-second output by timing a dosing run into a graduated cylinder rather than trusting the pump's rated flow, since tubing wear and head height change real output over time; recalibrate monthly as tubing ages.
Lighting Schedules
Most mid-range and higher reef LED fixtures accept either a 0-10V analog dimming signal or a digital control protocol — check your fixture's manual before assuming PWM-from-GPIO will work directly, since many fixtures need a proper 0-10V driver stage between the ESP32 and the light. A basic sunrise/sunset ramp (gradually increasing and decreasing intensity rather than a hard on/off) reduces fish and coral stress and is a simple time-based lookup table in firmware, no feedback sensor required.
Electronics Near Salt Water
Salt creep and humidity will find any exposed connector eventually. Keep all electronics — the ESP32 itself, relay boards, and especially any mains-voltage connections — outside the tank's splash zone in a sealed or conformally-coated enclosure, and route sensor and pump wiring with drip loops so condensation or a splash runs off the cable before it reaches a connector rather than wicking straight into it.