GSM Based Water Level Monitoring System | Arduino

We are going to construct a water level monitoring system which utilizes GSM network to send the status about the current level of water in a tank from 0 to 100% to owner’s phone. This project utilizes ultrasonic sensor to detect precise level of water present in the tank. We are using an Arduino board as brain for this project and a GSM modem to send and receive SMS.

We will see:

  • Overview.
  • How ultrasonic sensor can measure water level?
  • Circuit diagram of water level indicator.
  • Circuit description.
  • Arduino code for water level indicator.
  • How to send SMS to the circuit.
  • GSM water level indicator prototype.

Overview:

The proposed project can convey precise level of water in a tank in percentage from 0 to 100% by just sending an SMS command to the circuit. The circuit will respond with an SMS to owner’s phone instantly. In this way one can avoid claiming up to roof mounted tank to check water level every morning / evening. This project offers great convenience to elderly people who don’t live with their younger generation.    

Some apartments and houses especially the old one might have poorly maintained or very narrow stairs to reach roof mounted tank which could result in serious injury in case of a slip or rush.

This project utilizes non-contact method to measure level of water in the tank. Traditional contact based method like inserting electrodes into drinking water is not recommended since no electrode is ideal and there is risk of rusting and it is a common sense that consuming water with rust contamination in long run may cause health hazard. Moreover, electrode method can only show few levels of water in a tank and does not show water level in percentage.   

The proposed project overcomes these issues and offers more convenience to apartments, houses and commercial buildings.    

How ultrasonic sensor can be used for measuring water level?

Ultrasonic Sensor
Ultrasonic Sensor

Ultrasonic method to measure level of liquids in a tank is relatively an old method now; it is widely used in industries where liquids must not come in contact with the sensor. Here is a patent which describes how to measure liquids using ultrasonic setup:

Patent for liquid level indicator
Patent for liquid level indicator

In the patented diagram we can see a single transducer which is mounted directly above the liquid transmits and receives ultrasonic waves and we are getting pulses which are processed by a microcontroller to determine exact level of water / liquid in the tank. Measuring liquid levels is exactly same as measuring distance between the sensors and a solid, the measurement will be most accurate when the liquid stays still on the surface and there are several factors which could affect the measurement which are mentioned in the patent in depth. 

In this project we are using HC-SR04 which has two ultrasonic transducers instead on one, one of them transmit ultrasonic wave and other receives it. We will also receive pulses from ultrasonic sensor in this fashion:

Ultrasonic Sensor wave forms
Ultrasonic Sensor wave forms

We need to pull the trigger pin high for 10 microseconds by doing so one of the ultrasonic transducer will send acoustic bursts (8 pulses) at 40 KHz frequency. The 8 pulses propagate through air and reflect off an obstacle in this case water and reach the other transducer.

Meanwhile, as soon as the sensor finished sending 8 acoustic bursts, the echo pin turns high and when the reflected waves reaches back to the sensor the echo pin turns low. A microcontroller will measure how long echo pin stayed high i.e. time taken between sent and received waves. Using some elementary math and speed of sound in air, we can calculate precise distance between the sensor and the liquid.

The measured distance between the sensor and liquid can be converted in to a user friendly quantity like percentage.  

Circuit Diagram for Water Level Indicator:

GSM Based Water level Monitoring System
GSM Based Water level Monitoring System

Disconnect Tx and Rx pins before uploading code to Arduino.

Circuit Description:

The proposed circuit consists of just three components the Arduino board, the GSM modem and the ultrasonic sensor. The whole circuit can be powered from 9V supply with at-least 1A of current. The GSM board may consumes 1A at peak so it must be power from a 9V / 1A supply, additionally Arduino can also powered from the same 9V supply either through DC jack or via Vin pin.

The Tx and Rx of Arduino is connected with Rx and Tx of GSM respectively and ground connection is established between the two boards. The Trigger and Echo pins are connected to pin numbers 2 and 3 of Arduino respectively. The ultrasonic sensor HC-SR04 is powered from 5V output pin of Arduino.

Don’t forget to disconnect Tx and Rx pin from Arduino before uploading the code, otherwise you will get upload error.

Program Code:

// ------- Tank details ------//
const int total_height = 30; // Tank height in CM
const int hold_height = 25;// Water hold height in CM

//----- Your Phone no. -------//
char cntry_code[] = "+91"; // Country code
char ph[] = "xxxxxxxxxx"; // owner's phone no.

const int trigger = 2;
const int echo = 3;
int var_1 = 0;
char input_string[15];

long Time;
int distanceCM;
int resultCM;
int tnk_lvl = 0;
int sensr_to_wtr = 0;

void setup()
{
  Serial.begin(9600);
  pinMode(trigger, OUTPUT);
  pinMode(echo, INPUT);
  sensr_to_wtr = total_height - hold_height;

  delay(20000);
  delay(20000);
  delay(20000);
  
  Serial.println("AT+CNMI=2,2,0,0,0");
  delay(1000);
  Serial.println("AT+CMGF=1");
  delay(500);
  Serial.print("AT+CMGS=");
  Serial.print("\"");
  Serial.print(ph);
  Serial.println("\"");
  delay(1000);
  Serial.println("System is ready to receive SMS commands.");
  delay(100);
  Serial.println((char)26);
}

void loop()
{
  
}

void serialEvent()
{
  while (Serial.available())
  {
    if (Serial.find("/"))
    {
      delay(1000);
      while (Serial.available())
      {
        char input_char = Serial.read();
        input_string[var_1++] = input_char;
        if (input_char == '/')
        {
          if (!(strncmp(input_string, "status", 6)))
          {
            measure();
            Serial.print("AT+CMGS=");
            Serial.print("\"");
            Serial.print(cntry_code);
            Serial.print(ph);
            Serial.println("\"");
            delay(1000);
            Serial.print("Tank water level is: ");
            Serial.print(tnk_lvl);
            Serial.println("%");
            delay(100);
            Serial.println((char)26);
          }
          var_1 = 0;
          return;
        }
      }
    }
  }
}

void measure()
{
  delay(100);
  digitalWrite(trigger, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigger, LOW);
  Time = pulseIn(echo, HIGH);
  distanceCM = Time * 0.034;
  resultCM = distanceCM / 2;

  tnk_lvl = map(resultCM, sensr_to_wtr, total_height, 100, 0);
  if (tnk_lvl > 100) tnk_lvl = 100;
  if (tnk_lvl < 0) tnk_lvl = 0;
}

You need to enter the following details in the code:

  • You have to measure your water tank’s two heights in CM.

   // ------- Tank details ------//
const int total_height = 30; // Tank height in CM
const int hold_height = 25;// Water hold height in CM
  • You have to enter your country code and phone number to which you will receive tank’s water level.

//----- Your Phone no. -------//
char cntry_code[] = "+91"; // Country code 
char ph[] = "xxxxxxxxxx"; // owner's phone no.

How to mount ultrasonic sensor and measure tank height:

How to measure your tank correctly?

In any roof mounted water tank there are two heights 1) the actual water holding capacity height 2) total height of the tank.

Water level indicator using ultrasonic sensor
Water level indicator using ultrasonic sensor

The water holding capacity is nothing but the height up to which you can fill the tank, above this height there are overflow tube and pump inlet tube through which your tank gets filled.

The overflow tube prevents water going in reverse / back to inlet tube and it will also prevent water reaching the ultrasonic sensor since the sensor mentioned here is not water resistant. You need to enter these two heights in centimeter in the code, only then the circuit will able to reply with correct water level for your tank’s size.

For demonstration purpose I am going to use a mini water storage tank which measures 30 cm in height. I also marked imaginary water holding capacity height of 25 cm; this will emulate a real life water tank.

You should mount the ultrasonic sensor on top of the tank’s lid and sensor’s two transducers should parallel to surface of the water.

GSM based water level monitoring system
GSM based water level monitoring system

How to operate this circuit (send SMS and receive reply)?

  • With the completed setup turn ON the circuit, you will receive an SMS after one minute saying that the circuit is ready to receive requests from you. If you receive this SMS, your GSM module is latched to a cellular network and working fine. 
  • To check your tank’s water level you should send /status/ to the GSM module’s (SIM card) phone number.
  • The circuit will measure and reply an SMS to your phone number which you entered in the code.
  • Please note that your SMS should start and end with “/” and “status” should be in small letters, capital letters get rejected.

If you have any questions regarding this project, feel free to comments us below. You will get a guaranteed reply from us.