Projects / Tank fill control with float switches

Tank fill control with float switches

Beginner1.5 hGuided buildReviewed

Build it step by step

0 of 7 done
  1. NANO

    Mount the floats

    Low and high on the tank wall.

  2. NANO

    Test each float

    Print the state while you lift it.

  3. NANOON

    Wire the relay and pump

    Fuse and flyback diode.

  4. NANO

    Write the logic

    Start low, stop high.

  5. NANO

    Add the time limit

    Ten minutes.

  6. NANO

    Add the alarm

    Buzzer on fault.

  7. NANO

    Test with a bucket

    Run it with water.

In short

How do you build a tank fill control with float switches?

Two float switches run a pump between low and high levels, with a dry-run guard. You need Arduino Nano, Float switch (vertical) × 2, Relay Module 5V, 12 V DC water pump (diaphragm), 12 V 2 A DC adapter, Active buzzer 5 V and Rectifier Diode 1N4007. It takes 7 steps and about 90 minutes.

Level
Beginner
Time
About 90 min
Parts
7

Parts list

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

Wiring

FromToWhy
Low float switchNano D2 and GND (internal pull-up)Closed when water is above it
High float switchNano D3 and GND (internal pull-up)Closed when the tank is full
Relay INNano D5Pump control
Relay VCC and GNDNano 5V and GNDRelay power
12 V adapter plusFuse (2 A), relay COMPump supply
Relay NOPump plusSwitched 12 V
Pump minusAdapter minusReturn
1N4007 diodeAcross the pump, stripe to plusFlyback protection
BuzzerNano D6 and GNDAlarm

Code

Two floats give hysteresis: the pump starts when the water falls below the low float, and stops only when the water reaches the high float, so it does not chatter on and off around one level. A run-time limit of ten minutes is the dry-run guard; if the pump runs that long without the tank reaching the top, the source is empty or a pipe is blocked, so it stops and sounds the buzzer until the board is reset. The same alarm covers the impossible case of the high float closed while the low one is open. A relay module may need a driver that is active LOW; check your module and swap HIGH and LOW if needed. This is a 12 V low-voltage build; keep the electronics dry and away from the tank, mount the relay box above any water, and never use this to switch a mains pump unless a qualified electrician wires the mains side.

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).

// Tank fill control: pump on when below the low float, off at the high float, with a run-time limit.
// Board: Arduino Nano. Float switch closed (LOW) = water is at or above that float.
const int LOW_F = 2, HIGH_F = 3, RELAY = 5, BUZ = 6;
const unsigned long MAX_RUN = 10UL * 60UL * 1000UL;   // 10 minutes
bool pumping = false;
bool fault = false;
unsigned long startedAt = 0;
void setup() {
  pinMode(LOW_F, INPUT_PULLUP); pinMode(HIGH_F, INPUT_PULLUP);
  pinMode(RELAY, OUTPUT); pinMode(BUZ, OUTPUT);
  digitalWrite(RELAY, LOW);
}
void loop() {
  bool belowLow = digitalRead(LOW_F) == HIGH;          // open = water below the low float
  bool full = digitalRead(HIGH_F) == LOW;              // closed = full
  if (full && belowLow) fault = true;                  // impossible state: a float is stuck
  if (fault) {
    digitalWrite(RELAY, LOW); pumping = false;
    tone(BUZ, 1000); delay(300); noTone(BUZ); delay(700);
    return;
  }
  if (!pumping && belowLow) { pumping = true; startedAt = millis(); }
  if (pumping && full) pumping = false;
  if (pumping && millis() - startedAt > MAX_RUN) {     // water never arrived: dry source or a blocked pipe
    pumping = false; fault = true;
  }
  digitalWrite(RELAY, pumping ? HIGH : LOW);
  delay(200);
}

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
Water below low floatPump starts
Water reaches high floatPump stops
Source emptyPump stops after ten minutes and buzzer sounds
Floats swappedAlarm

If it does not work

Pump never starts

Check the float contact direction and the relay polarity.

Chatters

Raise the low float further below the high one.

Relay clicks but the pump is dead

Check the pump fuse and wiring.

Alarm on start

Reset the board after fixing the fault.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the tank fill control with float switches?

Arduino Nano, Float switch (vertical) × 2, Relay Module 5V, 12 V DC water pump (diaphragm), 12 V 2 A DC adapter, Active buzzer 5 V and Rectifier Diode 1N4007.

How long does the tank fill control with float switches take to build?

About 90 minutes for a beginner maker, in 7 steps.

How do I know the tank fill control with float switches works?

Water below low float: Pump starts. Water reaches high float: Pump stops. Source empty: Pump stops after ten minutes and buzzer sounds.

Pump never starts: what should I check?

Check the float contact direction and the relay polarity.

Chatters: what should I check?

Raise the low float further below the high one.

Relay clicks but the pump is dead: what should I check?

Check the pump fuse and wiring.

Alarm on start: what should I check?

Reset the board after fixing the fault.