ESP32

IoT based Water Level Monitoring System using ESP32, Waterproof Ultrasonic Sensor, & New Blynk

ESP32 and Waterproof Ultrasonic Sensor with new Blynk V2.0

IoT based Water Level Monitoring:

 

IoT based Water Level Monitoring System using ESP32, Waterproof Ultrasonic Sensor, & New Blynk- In today’s article, you will learn how to make an IoT based Water Level monitoring and motor control system using the ESP32 WiFi + Bluetooth module, and the waterproof JSN SR04T Ultrasonic Sensor.

IoT based Water Level Monitoring

Just don’t worry if you see AJ-SR04M printed on the module. JSN SR04T and AJ-SR04M are exactly the same the only difference is that the AJ-SR04M has an empty location for a resistor and the JSN SR04T doesn’t have it. The amazing thing about this Ultrasonic Sensor is that it comes with a long wire due to which it can be easily installed. Anyway, for this project, we will also need an SPDT-type relay to control a water pump and the new Blynk V2.0 for monitoring the water level.




Well, I have already written several articles on the water level monitoring system. But today’s IoT-based water level monitoring system is different from those projects, because many things have changed in the last few months. For example, Blynk V1.0, which was also known as Blynk Legacy, has now been replaced by the Blynk V2.0. Additionally, this time I am using the JSN SR04T Waterproof Ultrasonic Sensor instead of the normal HC-SR04 Ultrasonic Sensor.

IoT based Water Level Monitoring

Well, you can use any of these Ultrasonic sensors. But, technically speaking, if you are willing to spend more, then you should go for the JSN SR04T Waterproof Ultrasonic Sensor, because it is a more advanced ultrasonic sensor that has a longer sensing range of up to 6 meters, and a higher accuracy of up to 1mm. It operates at a wider voltage range of 3-5V DC and has a built-in temperature compensation feature that helps to improve accuracy even in varying temperatures. However, the JSN SR04T is relatively more expensive than the HC-SR04 Ultrasonic Sensor.

In Our House water tank is located at a significant height, so we cannot check the water level in the tank. This often leads to the water running out and with the frequent power outages in our area, it becomes very difficult once the water runs out. To avoid this situation, I have created a prototype model of a water level monitoring and motor control system.

IoT based Water Level Monitoring

With the help of this project, now I can monitor the water level from any part of the world. This is fully automatic. When the water level decreases below a certain level the motor is automatically turned ON and when the water level increases to a certain level then the motor is automatically turned OFF. You can think of this Bulb as the water pump. This is a 220Vac Bulb. If you want to control a large water pump then you can use a power relay. I already have an article on the IoT power relay. Now, let’s go ahead and take a look at the connections. So, without any further delay let’s get started!!!



Amazon Links:

JSN SR04T Waterproof Ultrasonic Sensor

HC-SR04 Ultrasonic Sensor

ESP32 WiFi + Bluetooth module

1-channel relay module

Other Tools and Components:

Top Arduino Sensors:

Super Starter kit for Beginners

Digital Oscilloscopes

Variable Supply

Digital Multimeter

Soldering iron kits

PCB small portable drill machines

*Please Note: These are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way!



Waterproof Ultrasonic Sensor with ESP32:

IoT based Water Level Monitoring

As usual, I am using my ESP32 development board. But you can also do the same exact connections on a breadboard. Out of these 4 relays, I am using only 1 relay, and it’s connected to the GPIO Pin 12.

IoT based Water Level Monitoring

The VCC and GND pins of the Waterproof ultrasonic sensor are connected to the ESP32 3.3V and GND pins. Whereas the Trigger and Echo pins are connected to the GPIO pins 25 and 26 respectively.

Now, let’s go ahead and start with the Blynk Web Dashboard Setup.



Blynk Web Dashboard Setup:

Go to Blynk.cloud website login page and register a free account and if you have already registered an account then simply enter your login credentials and click on the login button. Once you are logged in then click on the New Template.

IoT based Water Level Monitoring

Enter the name of the template, select the Hardware type, connections types, and you can also write some description. Finally, click on the Done button.

IoT based Water Level Monitoring

While the Datasreams is selected; click on the + New Datastream, and from the drop down menu select the Virtual Pin.

IoT based Water Level Monitoring

Then enter the credentials for the virtual pin and click on the create button

IoT based Water Level Monitoring




We just created a Datastream, its name is waterlevel, its Alias is waterlevel, Pin is V0, Data Type is Integer, etc.

IoT based Water Level Monitoring

In the similar way add another variable for the distance measurement. If still you find it difficult then you can watch the video tutorial given at the end of this article. Anyway, after you have created your two Datastreams then you can start be clicking on the Web Dashboard. On the Left-side you will see different widgets. Simple Drag and drop the widgets as per your needs. Since we have two Datastreams, so for now we will need two widgets. You can also add multiple widgets if you want to display the same values on different widgets.

IoT based Water Level Monitoring

Click on the gauge setting

IoT based Water Level Monitoring

Then give a title to the gauge, link the virtual pin V0 with the gauge, and click on the save button.

IoT based Water Level Monitoring

Then click on the label gadget to display the distance and click on the setting button

IoT based Water Level Monitoring

Then give a title to the label, link the virtual variable V1, and click on the save button.

IoT based Water Level Monitoring



So, after assigning the datastreams; click on the search button and click on the add new device.

IoT based Water Level Monitoring

Click on the From template

IoT based Water Level Monitoring

Then click on water level monitoring and click on the Create Button.

IoT based Water Level Monitoring

Then copy the credentials by clicking on the copy Code. Without these credentials we won’t be able to connect our ESP32 module with the Blynk V2.0. Your credentials will be different from mine.

IoT based Water Level Monitoring

Then paste these credentials in the programming; as you can see in the image given below.

IoT based Water Level Monitoring

Note: If this is your first time using the ESP32 WiFi + Bluetooth module then you should read my article on how to install the ESP32 board in the Arduino IDE.

If you want to know in depth about the ESP32 and the New Blynk V2.0. Then you should read my getting started article on the ESP32 and Blynk V2.0.



IoT based Water Level Monitoring ESP32 Code:

// Template ID, Device Name and Auth Token are provided by the Blynk.Cloud
// See the Device Info tab, or Template settings
#define BLYNK_TEMPLATE_ID "TMPL6e7l4H32E"
#define BLYNK_TEMPLATE_NAME "water level"
#define BLYNK_AUTH_TOKEN "YMHighdnF7kcho9YWKpLWbLIKURfhN6d"
// Comment this out to disable prints and save space
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

char auth[] = BLYNK_AUTH_TOKEN;

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "AndroidAP3DEC";
char pass[] = "electroniclinic";

//BlynkTimer timer;


#define BuzzerPin  12  //D12
#define trigPin 25
#define echoPin 26
int distance;
void setup()
{
 pinMode(trigPin, OUTPUT);
 pinMode(echoPin, INPUT);
 pinMode(BuzzerPin,OUTPUT);

  // Debug console
  Serial.begin(115200);

  Blynk.begin(auth, ssid, pass);

}

void loop()
{
  Blynk.run();
   // Clear the trigPin by setting it LOW:
  digitalWrite(trigPin, LOW);
  
  delayMicroseconds(5);

 // Trigger the sensor by setting the trigPin high for 10 microseconds:
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  
  // Read the echoPin. pulseIn() returns the duration (length of the pulse) in microseconds:
int  duration = pulseIn(echoPin, HIGH);
  
  // Calculate the distance:
//  distance = duration*0.034/2;
  
distance = (duration/2) / 29.1;
  // Print the distance on the Serial Monitor (Ctrl+Shift+M):
int waterLevelPer = map(distance,22,51, 100, 0);

  Serial.print("Distance = ");
  Serial.print(distance);
  Serial.println(" cm");
  Serial.println(waterLevelPer);
  Blynk.virtualWrite(V0,waterLevelPer);
  Blynk.virtualWrite(V1,distance);
   if (distance>45 ){
        digitalWrite(BuzzerPin, HIGH);
      Serial.println("Buzzer is turned on");
      }      
    
    if (distance <21){
     
        digitalWrite(BuzzerPin, LOW);
      
    }
}

On your side, make sure you change the SSID and Password, and also set the emptyTankDistance and fullTankDistance values. Anyway, finally, I clicked on the button. After uploading the code; I went back to the Blynk Dashboard to check if ESP32 was able to send values to the Blynk Dashboard. As expected, it worked. I was able to receive the value. Now, let’s go ahead and start with the Blynk IoT Mobile Application Setup.



Blynk IoT Mobile App setup:

Open the Blynk IoT application on your cell phone. “Make sure you use the same Gmail ID”.

IoT based Water Level Monitoring

Then click on the developer mode

IoT based Water Level Monitoring

Click on the water level monitoring

IoT based Water Level Monitoring




Click on the add button and gauge

IoT based Water Level Monitoring

Double click on the gauge

IoT based Water Level Monitoring

Click on the choose data stream

IoT based Water Level Monitoring



Select the variable you want to link to the gauge

IoT based Water Level Monitoring

Then give a title to the gauge and you can also play around with other parameters like the Alignment, Font Size, etc.

IoT based Water Level Monitoring

Then again click on the add button and insert label gadget which will be used to display the distance.

IoT based Water Level Monitoring

Then link the distance variable with it

IoT based Water Level Monitoring



Final look of the IoT based Water Level monitoring system Application

IoT based Water Level Monitoring

So, my mobile Application is also ready. Now, I am going to explain how to fix the Ultrasonic Sensor over the top of a water tank and how to calculate the water level percentage. So, let’s go ahead and do it.

Altium Designer + Altium 365 + Octopart:

Arduino LoRa Free SMS

Altium 365 lets you hold the fastest design reviews ever. Share your designs from anywhere and with anyone with a single click. it’s easy, leave a comment tagging your teammate and they’ll instantly receive an email with a link to the design. Anyone you invite can open the design using a web browser. Using the browser interface, you’re able to comment, markup, cross probe, inspect, and more. Comments are attached directly to the project, making them viewable within Altium designer as well as through the browser interface. Design, share, and manufacture, all in the same space with nothing extra to install or configure. Connect to the platform directly from Altium Designer without changing how you already design electronics. Altium 365 requires no additional licenses and comes included with your subscription plan.

Get real-time component insights as you design with Octopart built into Altium 365. Octopart is the fastest search engine for electronic parts and gives you the most up-to-date part data like specs, datasheets, cad models, and how much the part costs at different amounts etc. Right in the design environment so you can focus on your designs. Start with Altium Designer and Activate Altium 365. Search for electronic parts on Octopart.



Ultrasonic Sensor for the Water Level Percentage:

IoT based Water Level Monitoring

Let’s think of this Bucket as the Water Tank and we have to measure the water level inside this Tank. For this, first install the ultrasonic sensor. Then using the Blynk application check the distance value when the Tank is empty. I want my motor to turn ON before the tank completely gets empty. So, I am going to select 25cm as the trigger distance. So, when the water level inside the tank is at 25cm the motor will automatically turn ON.

IoT based Water Level Monitoring

Then fill the water tank to the desired level and check the distance value. Then reopen the code, update the values, and upload it again.

For the practical demonstration, watch the video tutorial given below.




Watch Video Tutorial:

 

Engr Fahad

My name is Shahzada Fahad and I am an Electrical Engineer. I have been doing Job in UAE as a site engineer in an Electrical Construction Company. Currently, I am running my own YouTube channel "Electronic Clinic", and managing this Website. My Hobbies are * Watching Movies * Music * Martial Arts * Photography * Travelling * Make Sketches and so on...

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button