Arduino Water Level Indicator: The Best Method to Measure!

From our STAR Makers: 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 until 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 mostly difficult to install. Most of the available systems use dipped electrodes or float switches, which prove to 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 compared to regular systems.

What are the stuff required to do this project?

  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. You can learn more about this ultrasonic sensor here.
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 tutorial from Jeff to learn to interface an ultrasonic sensor to Arduino.

STEP 1: Copy the 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.

//Coded by MATHEW VARGHESE
//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);
  delayMicroseconds(2);
  digitalWrite(trig, HIGH);
  delayMicroseconds(5);
  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: http://www.parallax.com/dl/docs/prod/acc/28015-PI...
  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;
}

STEP 2: Make 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’s tutorial for learning 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

STEP 3: Upload the code

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

STEP 4: Interfacing the ultrasonic sensor on the water tank

Fix the Ping sensor such that 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 between the Ping sensor and the rest of the circuitry. Do 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.

Arduino water level indicator

Aravind Jayan and Mathew Varghese – STAR Makers at DIY Hacking

 

-Submitted by Aravind Jayan and Mathew Varghese

Aravind is a student at Federal Institute of Science and Technology and Mathew is from Mar Athanasius College of Engineering, both are STAR Makers at DIY Hacking.

Recent Posts
Showing 5 comments
  • Mathew Varghese
    Reply

    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
    Reply

    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
    Reply

    You might wanna have a look on this board for battery powered projects: https://talk2.wisen.com.au/product-talk2-whisper-node-avr/

  • Hashim
    Reply

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

    • Gautam
      Reply

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

Leave a Comment

52 + = 56

Start typing and press Enter to search