Tank fill control with float switches
Build it step by step
0 of 7 doneMount the floats
Low and high on the tank wall.
Test each float
Print the state while you lift it.
Wire the relay and pump
Fuse and flyback diode.
Write the logic
Start low, stop high.
Add the time limit
Ten minutes.
Add the alarm
Buzzer on fault.
Test with a bucket
Run it with water.
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
- Development BoardsBuyArduino Nano × 1
- SensorsBuy
- InterfacesBuyRelay Module 5V × 1
- Motors & ActuatorsBuy
- PowerBuy
- Motors & ActuatorsBuy
- SemiconductorsBuy
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| Low float switch | Nano D2 and GND (internal pull-up) | Closed when water is above it |
| High float switch | Nano D3 and GND (internal pull-up) | Closed when the tank is full |
| Relay IN | Nano D5 | Pump control |
| Relay VCC and GND | Nano 5V and GND | Relay power |
| 12 V adapter plus | Fuse (2 A), relay COM | Pump supply |
| Relay NO | Pump plus | Switched 12 V |
| Pump minus | Adapter minus | Return |
| 1N4007 diode | Across the pump, stripe to plus | Flyback protection |
| Buzzer | Nano D6 and GND | Alarm |
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.
| Check | Expected |
|---|---|
| Water below low float | Pump starts |
| Water reaches high float | Pump stops |
| Source empty | Pump stops after ten minutes and buzzer sounds |
| Floats swapped | Alarm |
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 →
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.
