Projects / Cattle water trough refill controller

Cattle water trough refill controller

Beginner1.5 hGuided buildReviewed

Build it step by step

0 of 7 done
  1. NANOLM2596

    Set the buck module

    Feed 12 V and adjust the LM2596 output to 5.0 V.

  2. NANO

    Test the floats

    With a multimeter on continuity, lift each float and see when it closes.

  3. NANO

    Mount the floats

    Low float near the bottom, high float near the top of the trough.

  4. NANOON

    Wire the controller

    As in the table, with the pump on the relay's NO terminal and the flyback diode across it.

  5. NANO

    Bench test

    Hold the floats by hand. Low open starts the pump, high closed stops it.

  6. NANO

    Test the timeout

    Set MAX_RUN_MS to 20 seconds and run the pump on an empty source. The buzzer starts.

  7. NANO

    Fit it

    Put the electronics in a box above the trough, away from splashes.

In short

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

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
12 V adapter +LM2596 IN+ and relay COMSupply
LM2596 OUT+ (set to 5.0 V first)Nano 5V and relay VCC5 V for the logic
12 V adapter - and LM2596 -Nano GND, relay GND, pump -Common ground
Relay NOPump +Switched 12 V
1N4007 across the pumpCathode on pump +, anode on pump -Flyback diode
Relay INNano D6Pump control
Low float switchNano D2 and GNDClosed (LOW) when the water is above the low float
High float switchNano D3 and GNDClosed (LOW) when the trough is full
Buzzer + and -Nano D8 and GNDDry-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.

CheckExpected
Low float openPump starts
High float closedPump stops
Source emptyPump stops after the timeout and the buzzer pulses
Water returnsFault 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 →

Ask Lark AI

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.