DIY Water Level Monitoring System | ESP32 DEVKIT V1 Tutorial
Hello and welcome back. In this project, we will learn how to make a Water level monitoring system with ESP32 DEVKIT V1 board. For that, I have mainly used the HC05 Ultrasonic sensor to measure the water level To display the water levels, an LCD screen and LEDs will be added, giving you a clear visual indicator of the water status. There is also a relay module to control the water pump, which can be programmed to turn on and off automatically. Specially I have designed a PCB for this project with JLCPCB so we can use it without wires. One of the key features of this project is the integration of the Blynk cloud platform, enabling you to monitor and control the system remotely using your mobile phone or computer. This adds a layer of convenience and flexibility, making it easy to keep track of your water levels from anywhere.
If you want to use this project for a long time, please use a waterproof ultrasonic sensor. However, I’ve used an HC-SR04 ultrasonic sensor and a water bucket to demonstrate the system’s functionality for testing purposes. If you’re new to these components and need detailed, step-by-step instructions, be sure to check out our previous articles where we cover everything in depth.
Let’s make this project step by step. The required components are given below.
- ESP32 board x 1 — Our store / Amazon
- LCD screen x 1 — Our store / Amazon
- 3mm LED x 6 — Our store / Amazon
- 100 ohm Resistor x 6 — Our store / Amazon
- 5v Relay x 1 — Our store / Amazon
- Female header x 2 — Our store / Amazon
- Male header x 1 — Our store / Amazon
- Two-pin terminal x 1 — Our store / Amazon
- Three-pin terminal x 1 — Our store / Amazon
- 104 Preset x 1 — Our store / Amazon
- 102 SMD Resistor x 3 — Our store / Amazon
- 101 SMD Resistor x 1 — Our store / Amazon
- 2A Transistor x 1 — Our store / Amazon
- 1N4148 diode x 1 — Our store / Amazon
- Red SMD LED x 1 — Our store / Amazon
- Green SMD LED x 1 — Our store / Amazon
- Ultrasonic sensor x 1 — Our store / Amazon
- Jumper wires — Our store / Amazon
Disclosure: These Amazon links are Affiliate links. As an Amazon Associate, I earn from qualifying purchases.
Step 1
Firstly, identify these components.
Step 2
Secondly, let’s order PCBs for this project. Follow the instructions below for that.
- First, go to the JLCPCB official website and log in to your account. If you are a new member of this, please use this link. Then, you can get a 60$ new user coupon for orders to PCBs.
- JLCPCB PCB Fab & Assembly from $2! Sign up to Get $60 Coupons: —Click on me
- Now, click the instant quote button and upload the Gerber file. You can download it using the link below.
- Gerber file — Download
- I have ordered 5 PCBs with blue color. Then, select the build time and shipping. Finally, click the save to cart button.
Step 3
Thirdly unbox your PCB package and check it.
Step 4
Now solder the SMD components using the hot air gun.
Step 5
Then solder the other parts one by one. Use a soldering iron for that.
Step 6
Next, install the ESP32 board and LCD screen on the PCB. Then, connect the ultrasonic sensor to the PCB. For that, use the jumper wires.
Step 7
Now let’s set up the Blynk cloud. For that, follow the instructions below.
- First, go to the Blynk website and log into your account. If you are new to Blynk, please make a new account using your email address.
- Then create a new template. I have named it the “Water Level Monitoring System”.
- Now, click the datastreams tab and create two virtual pins. Please enter the height of your water tank to the maximum value of the V0 pin.
- Virtual Pin > Name – Water Level / PIN – V0 / MIN – 0 / MAX – 16 (Height of the water tank)
- Virtual Pin > Name – Relay / PIN – V1 / MIN – 0 / MAX – 1
- Next, go to the web dashboard tab. Then, drag and drop the Button and Guage widgets from the widget box.
- Then, click the one-by-one setting icons and select the datastream we created earlier. Also, you can change colors as you like. Afterward, click the save button.
- Now click the device tab and select the template we created earlier. Finally, we can see the Blynk ID, Name, and Auth token.
OK, the Blynk web dashboard is ready for you.
Step 8
OK, now let’s set up the Blynk mobile dashboard. For that, follow the instructions below.
- First, download and install the Blynk app on your smartphone. Then, log in to your account using your email and password.
- Next, click the template and add one gauge widget and one button widget to the dashboard. Next, customize these widgets as you like.
- And then, click the one-by-one widget and select the datastreams you created on the web dashboard. Also, you can change the colors as you like.
OK, the Blynk mobile dashboard is ready for you.
Step 9
Now, let’s set up the program for this project. For that, connect the ESP32 board to the computer.
- Then, copy and paste the following program to the Arduino IDE.
- Program and Gerber file — Download
- Blynk Library — Download
//Include the library files
#include <LiquidCrystal.h>
#define BLYNK_PRINT Serial
#include <Wire.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#define LED1 14
#define LED2 27
#define LED3 26
#define LED4 25
#define LED5 32
#define LED6 33
#define trig 12
#define echo 13
#define relay 22
//Enter your tank max value(CM)
int MaxLevel = 16;
int Level1 = (MaxLevel * 75) / 100;
int Level2 = (MaxLevel * 70) / 100;
int Level3 = (MaxLevel * 60) / 100;
int Level4 = (MaxLevel * 50) / 100;
int Level5 = (MaxLevel * 40) / 100;
int Level6 = (MaxLevel * 30) / 100;
//Initialize the LCD display
LiquidCrystal lcd(2, 4, 5, 18, 19, 21);
BlynkTimer timer;
// Enter your Auth token
char auth[] = "******************";
//Enter your WIFI SSID and password
char ssid[] = "***************";
char pass[] = "**************";
void setup() {
// Debug console
Serial.begin(115200);
Blynk.begin(auth, ssid, pass, "blynk.cloud", 80);
lcd.begin(16, 2);
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
pinMode(LED4, OUTPUT);
pinMode(LED5, OUTPUT);
pinMode(LED6, OUTPUT);
pinMode(trig, OUTPUT);
pinMode(echo, INPUT);
pinMode(relay, OUTPUT);
digitalWrite(relay, LOW);
lcd.setCursor(1, 0);
lcd.print("System Loading");
for (int a = 0; a <= 15; a++) {
lcd.setCursor(a, 1);
lcd.print(".");
delay(200);
}
lcd.clear();
}
//Get the ultrasonic sensor values
void ultrasonic() {
digitalWrite(trig, LOW);
delayMicroseconds(4);
digitalWrite(trig, HIGH);
delayMicroseconds(10);
digitalWrite(trig, LOW);
long t = pulseIn(echo, HIGH);
int distance = t / 29 / 2;
Serial.println(distance);
int blynkDistance = (distance - MaxLevel) * -1;
if (distance <= MaxLevel) {
Blynk.virtualWrite(V0, blynkDistance);
} else {
Blynk.virtualWrite(V0, 0);
}
lcd.setCursor(0, 0);
lcd.print("WLevel:");
if (Level1 <= distance) {
lcd.setCursor(8, 0);
lcd.print("Very Low");
digitalWrite(LED1, HIGH);
digitalWrite(LED2, LOW);
digitalWrite(LED3, LOW);
digitalWrite(LED4, LOW);
digitalWrite(LED5, LOW);
digitalWrite(LED6, LOW);
} else if (Level2 <= distance && Level1 > distance) {
lcd.setCursor(8, 0);
lcd.print("Low");
lcd.print(" ");
digitalWrite(LED1, HIGH);
digitalWrite(LED2, HIGH);
digitalWrite(LED3, LOW);
digitalWrite(LED4, LOW);
digitalWrite(LED5, LOW);
digitalWrite(LED6, LOW);
} else if (Level3 <= distance && Level2 > distance) {
lcd.setCursor(8, 0);
lcd.print("Medium");
lcd.print(" ");
digitalWrite(LED1, HIGH);
digitalWrite(LED2, HIGH);
digitalWrite(LED3, HIGH);
digitalWrite(LED4, LOW);
digitalWrite(LED5, LOW);
digitalWrite(LED6, LOW);
} else if (Level4 <= distance && Level3 > distance) {
lcd.setCursor(8, 0);
lcd.print("Medium");
lcd.print(" ");
digitalWrite(LED1, HIGH);
digitalWrite(LED2, HIGH);
digitalWrite(LED3, HIGH);
digitalWrite(LED4, HIGH);
digitalWrite(LED5, LOW);
digitalWrite(LED6, LOW);
} else if (Level5 <= distance && Level4 > distance) {
lcd.setCursor(8, 0);
lcd.print("Full");
lcd.print(" ");
digitalWrite(LED1, HIGH);
digitalWrite(LED2, HIGH);
digitalWrite(LED3, HIGH);
digitalWrite(LED4, HIGH);
digitalWrite(LED5, HIGH);
digitalWrite(LED6, LOW);
} else if (Level6 <= distance && Level5 > distance) {
lcd.setCursor(8, 0);
lcd.print("Full");
lcd.print(" ");
digitalWrite(LED1, HIGH);
digitalWrite(LED2, HIGH);
digitalWrite(LED3, HIGH);
digitalWrite(LED4, HIGH);
digitalWrite(LED5, HIGH);
digitalWrite(LED6, HIGH);
}
}
//Get the button value
BLYNK_WRITE(V1) {
bool Relay = param.asInt();
if (Relay == 1) {
digitalWrite(relay, HIGH);
lcd.setCursor(0, 1);
lcd.print("Motor is ON ");
} else {
digitalWrite(relay, LOW);
lcd.setCursor(0, 1);
lcd.print("Motor is OFF");
}
}
void loop() {
ultrasonic();
Blynk.run();//Run the Blynk library
}
- Now, enter the maximum height of your water tank. Then, copy and paste the Blynk Auth token. (You can find it on the Blynk web dashboard)
- Next, enter your WIFI SSID and password. Then, select the correct board and port. Finally, click the upload button.
Step 10
Now, adjust the LCD contrast value using the variable resistor. Then, install the ultrasonic sensor as you like. I have used the water bottle. Finally, power up it with a USB cable or an external 5VDC power supply. I used a 5V DC external power supply.
Ok, now you can check it by filling the water. Also, you can monitor and control this system using mobile and desktop dashboards.
Troubleshooting
- Check your WIFI SSID and password.
- Check the Blynk Auth token.
- Check DC voltage.
- Adjust the LCD contrast value.
- Install the Blynk library.
- Enter the height of the water tank.
- Verify the health of your components.
DIY Water Level Monitoring System | ESP32 DEVKIT V1 Tutorial