Projects / Non-contact tank level indicator

Non-contact tank level indicator

Beginner1 hGuided buildReviewed

Build it step by step

0 of 8 done
  1. NANO

    Fix the sensors

    Stick three on the outside wall at low, middle and high.

  2. NANO

    Wire power

    All three to 5V and GND.

  3. NANO

    Wire the outputs

    Low to D2, middle to D3, high to D4.

  4. NANO17.9 mA

    Wire the LEDs

    Red on D8, yellow on D9, green on D10, each through 330 ohm.

  5. NANO

    Upload the sketch

    The serial monitor shows three digits.

  6. NANO

    Fill the tank slowly

    Sensors turn on one by one from the bottom.

  7. NANO18.0 mA

    Watch the LEDs

    Red off, then yellow, then green as it fills.

  8. NANO18.0 mA

    Empty it

    The red LED lights when the bottom sensor is dry.

In short

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

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

Wiring

FromToWhy
Each sensor VCC wireNano 5VCheck the colours on your sensor label, usually red or brown
Each sensor GND wireNano GNDUsually black or blue
Low sensor output (yellow)Nano D2Near the bottom of the tank
Middle sensor output (yellow)Nano D3Half way up
High sensor output (yellow)Nano D4Near the top
Red LED through 330 ohmNano D8 to GNDLow level
Yellow LED through 330 ohmNano D9 to GNDHalf full
Green LED through 330 ohmNano D10 to GNDFull

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.

CheckExpected
Empty tankRed LED on
Half fullYellow LED on
FullGreen LED on
Upper sensor wet and lower dryAll LEDs blink
Sensor unpluggedReads 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 →

Ask Lark AI

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.