Build it step by step
0 of 8 doneFit the floats
One quarter, one half and near the top of the barrel.
Test each float in a bucket
Lift it by hand, a multimeter shows continuity.
Wire the floats
One lead to D2, D3 and D4, the other lead to GND.
Wire the LEDs
Red D6, yellow D7, green D8, each through 330 ohm.
Upload the sketch
Red blinks with empty floats.
Lift the lowest float
After three seconds red stays on.
Lift the middle then the top float
Yellow, then green.
Run the cable to the barrel
Seal the joints.
How do you build a rain barrel level lights?
Three float switches at different heights light three LEDs so you can see from the kitchen window how full the rain barrel is. You need Arduino Nano, Float switch (vertical) × 3, LED 5 mm red, LED 5 mm yellow, LED 5 mm green, Resistor 330 Ω × 3, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm). It takes 8 steps and about 90 minutes.
- Level
- Beginner
- Time
- About 90 min
- Parts
- 8
Parts list
- Development BoardsBuyArduino Nano × 1
- SensorsBuy
- SemiconductorsBuyLED 5 mm red × 1
- SemiconductorsBuyLED 5 mm yellow × 1
- SemiconductorsBuyLED 5 mm green × 1
- PassivesBuyResistor 330 Ω × 3
- PrototypingBuy
- PrototypingBuy
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| Low float switch (quarter) | Nano D2 to GND | Internal pull-up, closed when water reaches it |
| Middle float switch (half) | Nano D3 to GND | Internal pull-up |
| High float switch (full) | Nano D4 to GND | Internal pull-up |
| Red LED plus through 330 ohm | Nano D6 | Low level |
| Yellow LED plus through 330 ohm | Nano D7 | About half |
| Green LED plus through 330 ohm | Nano D8 | Full |
| LED minus legs | Nano GND | Common ground |
Code
A vertical float switch contains a magnet in a floating collar and a reed switch in a stem. When water lifts the float to the reed, the contacts close. The three switches sit at one quarter, one half and full height. Each is wired between a pin and ground, with the internal pull-up, so water at that height reads LOW. Waves make a float bounce, so a reading must hold steady for three seconds before the sketch accepts it. The LED logic then turns the three states into a simple picture: green is full, yellow is about half, red is about a quarter and blinking red is almost empty. If the pattern is impossible, for example the high float is up while the lower ones are down, all three LEDs blink, because a float is stuck or a wire has come loose. Only 5 V low-voltage wiring goes to the barrel. Run a thin two-core cable per switch, protect the joints with heat shrink or sealed connectors, and keep the Nano indoors, away from water.
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 uint8_t FLOAT_PIN[3] = {2, 3, 4}; // low, middle, high
const uint8_t LED_RED = 6, LED_YELLOW = 7, LED_GREEN = 8;
const unsigned long SETTLE_MS = 3000; // a reading must hold this long, waves come and go
bool stable[3] = {false, false, false}; // true means that float is lifted by water
bool candidate[3] = {false, false, false};
unsigned long since[3] = {0, 0, 0};
void setup() {
for (uint8_t i = 0; i < 3; i++) pinMode(FLOAT_PIN[i], INPUT_PULLUP);
pinMode(LED_RED, OUTPUT);
pinMode(LED_YELLOW, OUTPUT);
pinMode(LED_GREEN, OUTPUT);
}
void loop() {
for (uint8_t i = 0; i < 3; i++) {
bool wet = (digitalRead(FLOAT_PIN[i]) == LOW);
if (wet != candidate[i]) { candidate[i] = wet; since[i] = millis(); }
if (millis() - since[i] > SETTLE_MS) stable[i] = candidate[i];
}
bool low = stable[0], mid = stable[1], high = stable[2];
bool blinkOn = (millis() / 300) % 2 == 0;
bool r = false, y = false, g = false;
if ((high && !mid) || (mid && !low) || (high && !low)) {
r = y = g = blinkOn; // impossible pattern, a float is stuck or a wire is loose
} else if (high) {
g = true; // full
} else if (mid) {
y = true; // about half
} else if (low) {
r = true; // about a quarter
} else {
r = blinkOn; // below the lowest float: nearly empty
}
digitalWrite(LED_RED, r);
digitalWrite(LED_YELLOW, y);
digitalWrite(LED_GREEN, g);
}Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| All floats down | Red blinking |
| Low float up | Red steady |
| Low and middle up | Yellow |
| All three up | Green |
| Top up with the others down | All three blink |
If it does not work
LEDs flicker
Increase SETTLE_MS to ride out waves.
A level never shows
Check the float orientation, many have an up side marked.
Wrong LED lights
Check which float is on which pin.
All blink together
A lower float is not closing, check its wiring.
Corroded joints
Use sealed connectors and keep the Nano indoors.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the rain barrel level lights?
Arduino Nano, Float switch (vertical) × 3, LED 5 mm red, LED 5 mm yellow, LED 5 mm green, Resistor 330 Ω × 3, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm).
How long does the rain barrel level lights take to build?
About 90 minutes for a beginner maker, in 8 steps.
How do I know the rain barrel level lights works?
All floats down: Red blinking. Low float up: Red steady. Low and middle up: Yellow.
LEDs flicker: what should I check?
Increase SETTLE_MS to ride out waves.
A level never shows: what should I check?
Check the float orientation, many have an up side marked.
Wrong LED lights: what should I check?
Check which float is on which pin.
All blink together: what should I check?
A lower float is not closing, check its wiring.
