Non-contact tank level indicator
Build it step by step
0 of 8 doneFix the sensors
Stick three on the outside wall at low, middle and high.
Wire power
All three to 5V and GND.
Wire the outputs
Low to D2, middle to D3, high to D4.
Wire the LEDs
Red on D8, yellow on D9, green on D10, each through 330 ohm.
Upload the sketch
The serial monitor shows three digits.
Fill the tank slowly
Sensors turn on one by one from the bottom.
Watch the LEDs
Red off, then yellow, then green as it fills.
Empty it
The red LED lights when the bottom sensor is dry.
How do you build a non-contact tank level indicator?
Stick-on capacitive sensors detect the water level through the wall of a plastic tank without touching the water. You need Arduino Nano, Water level sensor (non-contact, XKC-Y25) × 3, LED 5 mm red, LED 5 mm yellow, LED 5 mm green, Resistor 330 Ω × 3 and Breadboard 830 Tie Points. It takes 8 steps and about 60 minutes.
- Level
- Beginner
- Time
- About 60 min
- Parts
- 7
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
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| Each sensor VCC wire | Nano 5V | Check the colours on your sensor label, usually red or brown |
| Each sensor GND wire | Nano GND | Usually black or blue |
| Low sensor output (yellow) | Nano D2 | Near the bottom of the tank |
| Middle sensor output (yellow) | Nano D3 | Half way up |
| High sensor output (yellow) | Nano D4 | Near the top |
| Red LED through 330 ohm | Nano D8 to GND | Low level |
| Yellow LED through 330 ohm | Nano D9 to GND | Half full |
| Green LED through 330 ohm | Nano D10 to GND | Full |
Code
Non-contact liquid sensors like the XKC-Y25 measure the tiny change in capacitance when water is on the other side of a plastic or glass wall, so nothing touches the water and nothing corrodes. Each sensor sits on the outside of the tank at the height you want to detect and gives a simple on or off output. Three sensors at low, middle and high give three levels: the red LED lights when the bottom sensor is dry, which means the tank is low, yellow means half full, and green means full. The sketch also checks that the readings make sense: a sensor higher up cannot be wet while a lower one is dry, so if that happens it blinks all three LEDs to warn of a wiring or placement problem. The sensors work through walls up to about 10 millimetres thick that are not metal, and they do not suit very thick or foil-lined tanks. Stick them firmly flat against the wall with no air gap, and keep them away from each other by at least a few centimetres. Check the output polarity of your sensor and change the constant if needed.
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 int SENSORS[] = {2, 3, 4}; // low, middle, high
const int LEDS[] = {8, 9, 10}; // red, yellow, green
const bool WET_IS_HIGH = true; // set to false if your sensor outputs LOW when it sees water
bool wet(int i) {
bool v = digitalRead(SENSORS[i]);
return WET_IS_HIGH ? v : !v;
}
void setup() {
for (int i = 0; i < 3; i++) { pinMode(SENSORS[i], INPUT); pinMode(LEDS[i], OUTPUT); }
Serial.begin(9600);
}
void loop() {
bool low = wet(0), mid = wet(1), high = wet(2);
// A higher sensor wet while a lower one is dry means a sensor or wiring fault
bool fault = (high && !mid) || (mid && !low) || (high && !low);
if (fault) {
bool on = (millis() / 250) % 2; // blink all three LEDs
for (int i = 0; i < 3; i++) digitalWrite(LEDS[i], on);
} else {
digitalWrite(LEDS[0], !low); // red when the bottom sensor is dry: tank low
digitalWrite(LEDS[1], mid && !high); // yellow when half full
digitalWrite(LEDS[2], high); // green when full
}
Serial.print(low); Serial.print(mid); Serial.println(high);
delay(200);
}What the serial monitor should show
Open the serial monitor at the baud rate in the code. This is what our simulator prints for a virtual Arduino Nano with its sensors at their default values. Your numbers will follow your real readings, but the format should match.
000
Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Empty tank | Red LED on |
| Half full | Yellow LED on |
| Full | Green LED on |
| Upper sensor wet and lower dry | All LEDs blink |
| Sensor unplugged | Reads dry, red on |
If it does not work
Readings inverted
Change WET_IS_HIGH to false.
Sensor never triggers
The wall is too thick or has an air gap, stick it flat.
Sensors trigger together
They are too close, space them further apart.
LEDs blink all the time
Check the order of the sensors from low to high.
False wet readings
A wet outside wall or a metal object nearby.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the non-contact tank level indicator?
Arduino Nano, Water level sensor (non-contact, XKC-Y25) × 3, LED 5 mm red, LED 5 mm yellow, LED 5 mm green, Resistor 330 Ω × 3 and Breadboard 830 Tie Points.
How long does the non-contact tank level indicator take to build?
About 60 minutes for a beginner maker, in 8 steps.
How do I know the non-contact tank level indicator works?
Empty tank: Red LED on. Half full: Yellow LED on. Full: Green LED on.
Readings inverted: what should I check?
Change WET_IS_HIGH to false.
Sensor never triggers: what should I check?
The wall is too thick or has an air gap, stick it flat.
Sensors trigger together: what should I check?
They are too close, space them further apart.
LEDs blink all the time: what should I check?
Check the order of the sensors from low to high.
