How to Make a Water Level Indicator with Arduino

By Aravind Jayan and Mathew Varghese

Arduino water level indicator


Knowing the amount of water in an overhead tank can be one tedious task. Usually, you’ll end up climbing up the stairs to the tank and checking the level manually or you’ll you hear the water overflowing from the top. But these days electronic water level indicators are available to fix this problem, but they often come with a hefty price tag and are usually difficult to install. Most of the available systems use dipped electrodes or float switches, which can be a headache in the long run. We present a different approach to knowing the water level using an Ultrasonic module with Arduino. The advantage of this method is that it is contactless, so issues like corrosion of the electrodes won’t affect this system. Furthermore, this Arduino water level indicator it is much easier to install than regular systems.

Required Materials

  1. ATMega328P microcontroller or Arduino board
  2. HC-SR04 Ultrasonic Ranging Module (aka PING sensor)
  3. 10K Resistor
  4. 16Mhz Crystal
  5. 22pf Disc capacitors: 2Nos
  6. Connecting wires
  7. LM7805 5V regulator
  8. 9V battery and connector
  9. 10uF electrolytic capacitor
  10. PCB or breadboard
  11. Wire stripper

Software needed: Arduino IDE

How Does it Work?

Range Finder


This Arduino water level indicator uses an ultrasonic sensor or Ping sensor to determine the level of water in the tank. The Ping sensor measures distance using sonar. An ultrasonic (well above human hearing) pulse is transmitted from the unit and distance-to-target is determined by measuring the time required for the echo return. Output from the Ping sensor is a variable-width pulse that corresponds to the distance to the target. This is then fed to the microcontroller that determines the water level and displays it through a series of LEDs.

The following project can be interfaced to an Arduino board if you have one or directly to an ATmega 328 microcontroller on a breadboard. You can also check out the DIY Hacking tutorial from Jeff to learn to interface an ultrasonic sensor to Arduino.

Code for the Arduino Water Level Indicator

Copy-paste the provided sketch in the Arduino IDE and find the line “ int d=18;” and change ‘18’ to the depth of your tank in centimeters.

//Note that the numbering of arduino pins are different from microcontroller pinout

int d = 18; //Enter depth of your tank here in centimeters

int trig = 11; // Attach Trig of ultrasonic sensor to pin 11
int echo = 10; // Attach Echo of ultrasonic sensor to pin 10
int pin1 = 2;//Highest level
int pin2 = 3;
int pin3 = 4;
int pin4 = 5;
int pin5 = 6;
int pin6 = 7;//Lowest evel

void setup() {
  pinMode (pin1, OUTPUT);// Set pins to output for controlling I/O
  pinMode (pin2, OUTPUT);
  pinMode (pin3, OUTPUT);
  pinMode (pin4, OUTPUT);
  pinMode (pin5, OUTPUT);
  pinMode (pin6, OUTPUT);

void loop()
{ digitalWrite(pin1, LOW);//Resetting the LEDs to off state
  digitalWrite(pin2, LOW);
  digitalWrite(pin3, LOW);
  digitalWrite(pin4, LOW);
  digitalWrite(pin5, LOW);
  digitalWrite(pin5, LOW);

  // Establish variables for duration of the ping,
  // and the distance result in inches and centimeters:
  long duration, in, cm;       //'in' is inches and 'cm' is centimeter

  // The PING is triggered by a HIGH pulse of 2 or more microseconds.
  // Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
  pinMode(trig, OUTPUT);
  digitalWrite(trig, LOW);
  digitalWrite(trig, HIGH);
  digitalWrite(trig, LOW);

  // The same pin is used to read the signal from the PING: a HIGH
  // pulse whose duration is the time (in microseconds) from the sending
  // of the ping to the reception of its echo off of an object.
  pinMode(echo, INPUT);
  duration = pulseIn(echo, HIGH);

  // Convert the time into a distance
  in = microsecondsToInches(duration);
  cm = microsecondsToCentimeters(duration);

delay(100);// To save battery,remove if felt inconvenient
  if (in < 6 * d / 7)//   Else is included to light only one led at a level and thus save battery charge
    digitalWrite(pin1, HIGH);
  else if (in < 5 * d / 6)
    digitalWrite(pin2, HIGH);
  else if (in < 4 * d / 6)
    digitalWrite(pin3, HIGH);
  else if (in < 3 * d / 6)
    digitalWrite(pin4, HIGH);
  else if (in < 2 * d / 6)
    digitalWrite(pin5, HIGH);
  else if (in < 1 * d / 6)
    digitalWrite(pin5, HIGH);

long microsecondsToInches(long microseconds)
  // According to Parallax's datasheet for the PING, there are
  // 73.746 microseconds per inch (i.e. sound travels at 1130 feet per
  // second). This gives the distance travelled by the ping, outbound
  // and return, so we divide by 2 to get the distance of the obstacle.
  // See:
  return microseconds / 74 / 2;

long microsecondsToCentimeters(long microseconds)
  // The speed of sound is 340 m/s or 29 microseconds per centimeter.
  // The ping travels out and back, so to find the distance of the
  // object we take half of the distance travelled.
  return microseconds / 29 / 2;

Making the Connections

Populate the circuit on a PCB or breadboard following the attached Fritzing diagram. This is for an ATMEga328 on a breadboard running Arduino.You can follow Mayoogh Girish’s tutorial to make your own Arduino board using ATMega328 on a breadboard. If you are using an Arduino board, you can just make the connections for the LEDs and the ultrasonic sensor as below.


Arduino water level indicator

Uploading the Code

Burn the code for the Arduino water level indicator directly onto the Arduino board or into an ATMega328P microcontroller. 

Interfacing the Ultrasonic Sensor on the Water Tank

Fix the Ping sensor so it directly faces the water in the tank. The main control board with indication LEDs can be fixed inside the home at any comfortable position. Any multi-cored cables (ethernet cable) can be used to connect the Ping sensor and the rest of the circuitry. Keep in mind not to increase the length between the components more than 20mts.

Now just hook up a battery and your Contactless arduino water level indicator is ready for use.

Recent Posts
Showing 20 comments
  • Luis Medina

    About the sensor, what about putting it inside lets say an acrylic box?

  • Stephanie

    I’m not sure I understand which components are required if using an Arduino board : just the ultrasonic sensor, the LEDs, and the battery?

    • Colin

      Someone answer her question please, i don’t understand what do i need if i have a arduino either.

      • Stephanie

        I figured it out. To do this project with an Arduino, you only need the sensor, the LEDs, and the battery with connector . You connect a wire from the 5V pin on the Arduino to + on the breadboard, and a wire from ground on the Arduino to – on the breadboard, as usual. If your battery connector looks like the one used in this tutorial, then you plug the red wire into the Vin pin on the Arduino, and the black wire into another one of the Arduino’s ground pins. Other battery connectors plug directly into the Arduino’s power connector.

        You can also run this project by connecting the USB cable from the Arduino to your computer (it only requires 5Volts).
        Alternatively, you can plug it into an electrical socket using a DC Power adapter (5V to 12V), and power it that way.

        The reason this tutorial uses an ATMega328P microcontroller and some other components is because the authors are making a stripped-down board that consumes less power than an Arduino. Arduinos have extra components like voltage regulators, a USB bridge, LEDs that are always on, etc, that will cause a battery to drain rather quickly. I did this project with an Arduino Uno, and my 9V battery was half drained in 12 hours.

        • Colin

          Still cant get it to work D:

          i have pin 2,3,4 to red yellow green respectively.
          + side connected to the pins and – side connected to ground.
          Connected pin10 and 11 to the sensor echo and trigg and vcc and gnd to 5v and gnd of the arduino
          ran the program and cant get it to work

  • Akhiles sarasijan

    Can someone help me out I followed the diagram …but for testing alone I used 2 led….and connected them to pin 2 and pin 7. But the code is for 6 LEDs…..I don’t know whether that would create error but plz help me……..tell me the connections for sensor to arduino and breadboard

  • Colyn

    A while ago, I built LED lights for a fish tank. Since moisture is a big issue in the canopy, I suck dry air from outside and continuously blow it over the LEDs with a small fan. It has not been years yet, but so far I have no indication of moisture damage on the LEDs. Worth a try I’m sure

  • Chris

    Great in theory. In the real world the sensor fails after a couple of weeks from condensation. I’ve been through 5 of them.

    • Mathew Varghese

      Try the one mentioned in Atif’s reply message(Scroll down). It works for me till now. (above 6 months)

  • GRousseau

    Work great. Thanks.

    However, you have two small mistakes in your code, under the loop section, where you never use pin6. You actually work with pin5 twice instead.

  • fathima

    what is the function of the capacitors here sir??

    • Mathew Varghese

      They are for decoupling. ie they act as short circuit when some voltage spikes occur in the supply voltage due to unanticipated reasons. The circuit works without them, but not always.

  • Mathew Varghese

    I tried this in my water tank using hobby module SR-04. It worked for about 3 months in the first try. Then the sensor got damaged.I guess humidity is the problem. I ordered a waterproof ultrasonic sensor( The one that is used in cars) from aliexpress. Its working fine for 1 month now. I dont know for how long it’ll last.

  • Larry fostano

    Not sure this would be applicable to monitor the water lever of a well that is 40 to 80 feet deep 6″ casing and the pump sitting 6’down .More than likely would ping off the pump connection before the water level

  • PDerek

    You might wanna have a look on this board for battery powered projects:

  • Hashim

    Its works great but the sensor damaged within 2 weeks (Transmitter/receiver moisture damage)

    • Gautam

      How did you mount it? Ours has been running for close to a month now

      • Chis

        Give it time.

Leave a Comment

1 + 9 =

Start typing and press Enter to search