IoT based water level Indicator using ESP8266

IoT based water level Indicator

IoT based water level Indicator

In up coming years water is going to be priceless. In many countries government is running are several projects to save water. We should understand and start conserving water to deal with scarcity of water in up coming years.

IoT based water level Indicator is such a project, which can be use to reduce wastage of water and save electricity as well.

IoT based water level Indicator

This project is different from most of the other projects available on the internet. This project doesn’t require any sensor to be inserted inside water tank.

How it works?

This project uses ultrasonic sensor which measures the water level. The data is sent to Arduino as well as ESP8266 wifi module.

Iot based water level monitoring

The WiFi module is connected to internet and shares the data to Blynk platform. This data is displayed on real time basis.

Over smart phone using Blynk app you can see the water level. With few modification you can get approximate liters of water available in the tank.

We are going to use ESP8266-01 WiFi module and Blynk IoT app for monitoring.

Parts List

  1. ESP8266-01 Module x 1
  2. Arduino Pro Mini x 1
  3. 5V SMPS power supply x 1
  4. Ultrasonic Sensor x 1
  5. Buzzer (Optional) x 1
  6. Resistor 330Ω x 1
  7. Transistor BC547 x 1
  8. 3.3V Regulator LD33V x 1
  9. 4 Core Long Cable
  10. LED x 5
  11. Box to mount entire project x 1

This project will allow you to monitor the water level of an overhead tank or underground sump. You can configure to auto start / stop the pump or motor based on water level.

Sensors and Modules Functions

Arduino Pro mini

arduino-pro-mini

This module is used for getting the data and showing it with the help of LED’s. This also shows even if there is no internet connection. Arduino pro mini helps this project to work offline.

ESP8266 – 01

ESP8266-01

This wifi modules helps in collecting the water level and sent it to blynk app via internet. You can configure with other IoT platforms as well.

Ultrasonic sensor

Ultrasonic_sensor

This module measures the height of the water level from the top of the tank and sends the data to both Arduino and ESP8266 for further processing.

Blynk Setup

To setup using blynk you have to follow some simple steps 

Tap on New Project

Blynk config

Enter Project name and select device as shown. Tap on Create

Blynk config

Once you Tap on Create you will get Auth Token on your Registered Email

IoT based water level Indicator

Tap on the Icon highlighted to add Widget

Blynk config

Scroll down and select “Level V” from widget Box

IoT based water level Indicator

Configure with the below configurations

Blynk config

Tap on PIN and select Virtual and select V5

Blynk config

Finally your configuration is complete

IoT based water level Indicator

 

Circuit Diagram

You can build this is project in a normal PCB or you can create your custom PCB.

IoT based water level Indicator

Codes

You can download the code from this link.

There are two codes in this project. As we are using Arduino and ESP8266, hence individual code has to be uploaded.

Code for Arduino

/*
HC-SR04 ultrasonic sensor
VCC to arduino 5v
GND to arduino GND
Echo to Arduino pin 9
Trig to Arduino pin 8
*/
#define echopin 9 // echo pin
#define trigpin 8 // Trigger pin

int maximumRange = 105; // maximum height of tank in cm
long duration;
float v; // volume in cubic cm
float distance; // height of water level in cm
int r = 53.2; // radius of tank in cm
int cap; // capacity in liters
int actual_height; // actual height in cm

void setup()
{
Serial.begin (9600);
pinMode (trigpin, OUTPUT);
pinMode (echopin, INPUT );
pinMode (4, OUTPUT); //Buzzer
pinMode (6, OUTPUT); //PUMP control
pinMode (A0, OUTPUT); //0% indicator
pinMode (A1, OUTPUT); //25% indicator
pinMode (A2, OUTPUT); //50% indicator
pinMode (A3, OUTPUT); //75% indicator
pinMode (A4, OUTPUT); //100% indicator

}
void loop ()
{
digitalWrite(trigpin,LOW);
delayMicroseconds(2);
digitalWrite(trigpin,HIGH);
delayMicroseconds(10);
duration=pulseIn (echopin,HIGH);
distance= duration/58.2;
delay(200);
Serial.print(distance);
Serial.println(“cm”);
/*Serial.print(v);
Serial.println(“cm3,”);
Serial.print(cap);
Serial.println(“liters, “);*/
actual_height = maximumRange – distance;
v = ((3.14*(r*r))*(actual_height)); // formula to calculate volume in cubic cm
cap = v/1000; // final capacity in liters

if (distance <= 100)
{
digitalWrite(A0,HIGH); // 0% INDICATION

if (distance > 81) //buzzer action
{
digitalWrite(4,HIGH);
delay(200); //BUZZER BEEPING
digitalWrite(4,LOW);
delay(200);
}
else
{
digitalWrite(4,LOW); //BUZZER OFF
}
}
else
{
digitalWrite(A0,LOW);
}

if (distance <= 80) // 25% INDICATION
{
digitalWrite(A1,HIGH);
}
else
{
digitalWrite(A1,LOW);
}

if (distance <= 60) // 50% INDICATION
{
digitalWrite(A2,HIGH);
}
else
{
digitalWrite(A2,LOW);
}

if (distance <= 40) // 75% INDICATION
{
digitalWrite(A3,HIGH);
}
else
{
digitalWrite(A3,LOW);
}

if (distance <= 20) // 100% INDICATION
{
digitalWrite(A4,HIGH);
//digitalWrite(6,LOW); //PUMP OFF
}
else
{
digitalWrite(A4,LOW);
}
}

************************************************

/*
************************************************
Code for ESP8266-01
************************************************
*/
//#define TRIGGER 4
//#define ECHO 5

#define TRIGGER 0 // for esp8266-01
#define ECHO 2 // for esp8266-01

// Pin D1 –> ECHO | NodeMCU Pin D2 –> TRIGGER

//#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Blynk.h>

int maximumRange = 105; // maximum height of tank in cm
long duration;
float v; // volume in cubic cm
float distance; // height of water level in cm
int r = 53.2; // radius of tank in cm
int cap; // capacity in liters
int actual_height; // actual height in cm

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = “Your Auth Token”;

// Your WiFi credentials.
// Set password to “” for open networks.
char ssid[] = “Your SSID”;
char pass[] = “Your WiFi Password”;

// Keep this flag not to re-sync on every reconnection
bool isFirstConnect = true;

// This function will run every time Blynk connection is established
BLYNK_CONNECTED() {
if (isFirstConnect) {
// Request Blynk server to re-send latest values for all pins
Blynk.syncAll();
isFirstConnect = false;
}
}
BLYNK_WRITE(V5)
{
int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
}
void setup() {
// Serial.begin (9600);
Blynk.begin(auth, ssid, pass);
pinMode(TRIGGER, OUTPUT);
pinMode(ECHO, INPUT);
}
void loop() {
{
//long duration, distance;
digitalWrite(TRIGGER, LOW);
delayMicroseconds(2);

digitalWrite(TRIGGER, HIGH);
delayMicroseconds(10);

digitalWrite(TRIGGER, LOW);
duration = pulseIn(ECHO, HIGH);
distance= duration/58.2;
delay (50);
actual_height = maximumRange – distance;
v = ((3.14*(r*r))*(actual_height)); // formula to calculate volume in cubic cm
cap = v/1000; // final capacity in liters
Blynk.virtualWrite(V5, cap);
delay(200);
}
if (distance <= 105)
{
Blynk.virtualWrite(V0, 255);
//digitalWrite(D4,HIGH);
}
else
{
Blynk.virtualWrite(V0, 0);
//digitalWrite(D4,LOW);
}

if (distance <= 85)
{
Blynk.virtualWrite(V1, 255);
//digitalWrite(D5,HIGH);
}
else
{
Blynk.virtualWrite(V1, 0);
//digitalWrite(D5,LOW);
}

if (distance <= 65)
{
Blynk.virtualWrite(V2, 255);
//digitalWrite(D6,HIGH);
}
else
{
Blynk.virtualWrite(V2, 0);
//digitalWrite(D6,LOW);
}

if (distance <= 45)
{
Blynk.virtualWrite(V3, 255);
//digitalWrite(D7,HIGH);
}
else
{
Blynk.virtualWrite(V3, 0);
//digitalWrite(D7,LOW);
}

if (distance <= 20)
{
Blynk.virtualWrite(V4, 255);
//digitalWrite(D8,HIGH);
}
else
{
Blynk.virtualWrite(V4, 0);
//digitalWrite(D8,LOW);
}

Blynk.run();
}

*************************************************

Calculation of Water In Liters

IoT based water level Indicator

In this project we are taking a cylindrical water tank. The formula to calculate the volume of the tank is 

Volume = π  x  r² x h

Where

π = 3.14

r = Radius of the tank (Base of tank) you can find the diameter and divide it by 2 to get the radius in cm.

h = Height of the tank in cm.

The value of “r” will be static once you get it. The value of “h” will depend on the water level and it will be dynamic.

Now if you get the value of “r” and “h” and apply to the formula then you will get the volume of water in the tank in cubic centimeters.

To calculate the amount of water in the tank in liters we have to use the below formula

Capacity = Volume/1000 liters

Now you can use capacity variable to display the data to LCD or OLED or any app easily.

Testing

 

Conclusion

This project will help you to understand the concepts of measurement using ultrasonic sensor along with interfacing it with blynk using ESP8266 and Arduino. This project is economical and can be used in real time.

Stay tuned for new projects. Save water, Save electricity, Avoid Plastics and Save environment.

Leave a Reply