Project showcase
Water Level Meter

Water Level Meter

Water Level Meter using the Ultrasonic Sensor to sense the Water Level and ESP8266-01 to send the data over WiFi.

  • 6,391 views
  • 6 comments
  • 20 respects

Components and supplies

A000053 iso both1
Arduino Micro & Genuino Micro
I have used Pro-Micro. There is no library of ESP8266-01 for Arduino Micro
×1
Esp01
Everything ESP ESP8266 ESP-01
×1
51gzz5eu9pl. sx425
Ultrasonic Sensor - HC-SR04 (Generic)
×1

Necessary tools and machines

Hy gluegun
Hot glue gun (generic)
09507 01
Soldering iron (generic)

Apps and online services

Ide web
Arduino IDE
Vs2015logo
Microsoft Visual Studio 2015
Used for HTML Code testing

About this project

Water Level Meter by Fanatic Series

The idea is to make a sensor which can sense the water levelin tanks where the motor pumps are used. There is no specific method to checkthe level of the water. The project under discussion has the capability to checkthe water level and also send the data over WiFi.

To check the water level, ultrasonic HC-SR04 is the distancesensor. The waves are tranismittd and received by the module and calculate thenext obstacle

For transmission over WiFi, ESP8266-01 is used. It is configured by the AT Commands. The ESP connect with the Access point and becomes Web Server. When the specified IP of the ESP module browsed, HTML page which specify the water level.

Code

Water Level Meter using Ultrasonic HC-SR04 and WiFi module ESP-8266-01Arduino
#include <SoftwareSerial.h>
#define DEBUG true  
#define dbg Serial  // USB local debug
#define trigPin 5  //IO of Ultrasonic Sensor
#define echoPin 6  //IO of Ultrasonic Sensor
long duration;  
float distance;
const int max_hight=30;  // maximum deapth of the Water Tank. in my case its a bucket

String ssid = "SSID";

String pass = "PASSWORD";
String ip = "192.168.1.202";  //desired IP Address
String ref="refresh";         //Text for refeshing the HTML Page  
String num_delay = "3";		// Delay is second to refresh the HTML Page	

String sendData(String command, const int timeout, boolean debug) {
  String response = "";
  Serial1.print(command); // send the read character to the esp8266
  long int time = millis();
  while ( (time + timeout) > millis()) {
    while (Serial1.available()) {
      // The esp has data so display its output to the serial window
      char c = Serial1.read(); // read the next character.
      response += c;
    }
  }

  if (debug)
  {
    Serial.print(response);
  }

  return response;
}





void setup() {

  // Set baud rates
  pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input

  Serial1.begin(115200);
  dbg.begin(115200);
  dbg.println("DEBUG: Running Setup");



  sendData("AT+RST\r\n", 2000, DEBUG); // reset module
  sendData("AT\r\n", 2000, DEBUG); // reset module
  sendData("AT+CWMODE=1\r\n", 1000, DEBUG); // configure as access point

sendData("AT+CWJAP=\"" + ssid + "\",\"" + pass + "\"\r\n", 6000, DEBUG); // configure as access point
sendData("AT+CIPSTA=\""+ip+"\"\r\n",1000,true); // configure softAPip address
sendData("AT+CIPMUX=1\r\n",1000,DEBUG); // configure for multiple connections
sendData("AT+CIPSERVER=1,80\r\n",1000,DEBUG); // turn on server on port 80




delay(1000);


  dbg.println("DEBUG: Setup complete\n\n");
}


void loop()
{


  
  if(Serial1.available()) // check if the esp is sending a message 
  {
    Serial.println("hello");
    //delay(1000);

    /*
    while(Serial1.available())
    {
      // The esp has data so display its output to the serial window 
      char c = Serial1.read(); // read the next character.
      Serial.write(c);
    } */
    
    if(Serial1.find("+IPD,"))
    {
     delay(1000);
     sensor_data();
     String data = String((int)distance);
     String webpage="";
 
     int connectionId = Serial1.read()-48; // subtract 48 because the read() function returns 
                                           // the ASCII decimal value and 0 (the first decimal num_delayber) starts at 48
String colorgreen="background-color:green;";  //#87F467- Green, #FF7979-Red
String colorred="background-color:red;";  //#87F467- Green, #FF7979-Red

  if(distance<=10 || distance>=90){webpage="<html><body style=\""+colorred+"\"></body>";}
  else {webpage="<html><body style=\""+colorgreen+"\"></body>";}
  webpage+="<meta http-equiv=\""+ref+ "\" content=\"" + num_delay+ "\"/> <h1><center>WATER LEVEL<\center></h1> <h2><center>"+String(data)+" %<\center></h2><\html>";


     String cipSend = "AT+CIPSEND=";
     cipSend += connectionId;
     cipSend += ",";
     cipSend +=webpage.length();
     cipSend +="\r\n";
     
     sendData(cipSend,1000,DEBUG);
     sendData(webpage,1000,DEBUG);
     
//Serial.println(webpage);   


 
     String closeCommand = "AT+CIPCLOSE="; 
     closeCommand+=connectionId; // append connection id
     closeCommand+="\r\n";    
     sendData(closeCommand,3000,DEBUG);
    //Serial.println("send0");
    //delay(2000);
    }
    
  }
}
       
  
  // END - Borrowed Code


  void sensor_data()
  {
    
  digitalWrite(trigPin, LOW);  // Added this line
  delayMicroseconds(2); // Added this line
  digitalWrite(trigPin, HIGH);
//  delayMicroseconds(1000); - Removed this line
  delayMicroseconds(10); // Added this line
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration/2) / 29.1;
    distance=max_hight-distance;
    distance=(distance/max_hight)*100;
    
    
    }

Schematics

Water Level Meter using Ultrasonic HC-SR04 and WiFi module ESP-8266-01
fritzing_breadboard_BTQUNfQzb8.fzz
Water Level Meter using Ultrasonic HC-SR04 and WiFi module ESP-8266-01
Water level meter schematic mlql5olpht

Comments

Similar projects you might like

Arduino Bluetooth Basic Tutorial

by Mayoogh Girish

  • 454,623 views
  • 42 comments
  • 236 respects

Home Automation Using Raspberry Pi 2 And Windows 10 IoT

Project tutorial by Anurag S. Vasanwala

  • 285,519 views
  • 95 comments
  • 671 respects

Security Access Using RFID Reader

by Aritro Mukherjee

  • 229,382 views
  • 38 comments
  • 236 respects

OpenCat

Project in progress by Team Petoi

  • 195,999 views
  • 154 comments
  • 1,363 respects
Add projectSign up / Login