Cattle water trough refill controller
Build it step by step
0 of 7 doneSet the buck module
Feed 12 V and adjust the LM2596 output to 5.0 V.
Test the floats
With a multimeter on continuity, lift each float and see when it closes.
Mount the floats
Low float near the bottom, high float near the top of the trough.
Wire the controller
As in the table, with the pump on the relay's NO terminal and the flyback diode across it.
Bench test
Hold the floats by hand. Low open starts the pump, high closed stops it.
Test the timeout
Set MAX_RUN_MS to 20 seconds and run the pump on an empty source. The buzzer starts.
Fit it
Put the electronics in a box above the trough, away from splashes.
How do you build a cattle water trough refill controller?
Two float switches keep a trough between low and full by running a pump, and a buzzer warns if the pump runs too long because the source is dry. You need Arduino Nano, Float switch (vertical) × 2, Relay Module 5V, 12 V DC water pump (diaphragm), Rectifier Diode 1N4007, 12 V 2 A DC adapter, Active buzzer 5 V, LM2596 Buck Module and Jumper wires male to male (40 pcs, 20 cm). It takes 7 steps and about 90 minutes.
- Level
- Beginner
- Time
- About 90 min
- Parts
- 9
Wiring
| From | To | Why |
|---|---|---|
| 12 V adapter + | LM2596 IN+ and relay COM | Supply |
| LM2596 OUT+ (set to 5.0 V first) | Nano 5V and relay VCC | 5 V for the logic |
| 12 V adapter - and LM2596 - | Nano GND, relay GND, pump - | Common ground |
| Relay NO | Pump + | Switched 12 V |
| 1N4007 across the pump | Cathode on pump +, anode on pump - | Flyback diode |
| Relay IN | Nano D6 | Pump control |
| Low float switch | Nano D2 and GND | Closed (LOW) when the water is above the low float |
| High float switch | Nano D3 and GND | Closed (LOW) when the trough is full |
| Buzzer + and - | Nano D8 and GND | Dry-run alarm |
Code
Arduino IDE, board "Arduino Nano" (processor ATmega328P, or ATmega328P (Old Bootloader) for clones). No libraries. Float switch contacts close when the float is up or down depending on how you mount them, so test with a multimeter and flip the logic if needed. Everything is 12 V DC. Set the LM2596 to exactly 5.0 V on a multimeter before connecting the Nano. Use a sealed box above the trough, and run the pump hose so water cannot back-siphon.
Runs on a virtual Arduino Nano 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).
const byte LOW_SW = 2, HIGH_SW = 3, RELAY = 6, BUZZ = 8;
const unsigned long MAX_RUN_MS = 10UL * 60UL * 1000UL; // longest allowed run
bool pumping = false, fault = false;
unsigned long startedAt = 0;
void setup() {
pinMode(LOW_SW, INPUT_PULLUP); pinMode(HIGH_SW, INPUT_PULLUP);
pinMode(RELAY, OUTPUT); digitalWrite(RELAY, HIGH); // relay off, most modules are active low
pinMode(BUZZ, OUTPUT);
}
void loop() {
bool waterAboveLow = digitalRead(LOW_SW) == LOW;
bool full = digitalRead(HIGH_SW) == LOW;
if (!fault) {
if (!pumping && !waterAboveLow) { pumping = true; startedAt = millis(); } // low: start the pump
if (pumping && full) pumping = false; // full: stop
if (pumping && millis() - startedAt > MAX_RUN_MS) { pumping = false; fault = true; } // too long: the source is probably dry
} else if (waterAboveLow) {
fault = false; // water returned, clear the fault
}
digitalWrite(RELAY, pumping ? LOW : HIGH);
digitalWrite(BUZZ, fault ? (millis() / 500) % 2 : LOW);
delay(100);
}Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Low float open | Pump starts |
| High float closed | Pump stops |
| Source empty | Pump stops after the timeout and the buzzer pulses |
| Water returns | Fault clears |
If it does not work
Pump runs backwards in logic
The floats close the other way. Flip the logic constants.
Pump chatters
Water sloshes around the floats. Use a stilling tube or add a short delay.
Relay does not click
Check the 5 V supply and the relay IN wiring.
Buzzer sounds with water present
A float is stuck. Check it moves freely.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the cattle water trough refill controller?
Arduino Nano, Float switch (vertical) × 2, Relay Module 5V, 12 V DC water pump (diaphragm), Rectifier Diode 1N4007, 12 V 2 A DC adapter, Active buzzer 5 V, LM2596 Buck Module and Jumper wires male to male (40 pcs, 20 cm).
How long does the cattle water trough refill controller take to build?
About 90 minutes for a beginner maker, in 7 steps.
How do I know the cattle water trough refill controller works?
Low float open: Pump starts. High float closed: Pump stops. Source empty: Pump stops after the timeout and the buzzer pulses.
Pump runs backwards in logic: what should I check?
The floats close the other way. Flip the logic constants.
Pump chatters: what should I check?
Water sloshes around the floats. Use a stilling tube or add a short delay.
Relay does not click: what should I check?
Check the 5 V supply and the relay IN wiring.
Buzzer sounds with water present: what should I check?
A float is stuck. Check it moves freely.
