How to make a water level monitoring system with ESP32 board and Blynk

How to make a water level monitoring system with ESP32 board and Blynk

Hello and welcome back. In this project, we will learn how to make a water level monitoring system with an ESP32 board and the Blynk app. For that, I mainly used an ultrasonic sensor to get the water levels. Also, we can control this system using our smartphone or computer. I used Blynk Cloud for that.

In this project, I used an HC-SR04 ultrasonic sensor. However, I highly recommend opting for a waterproof ultrasonic sensor. This choice ensures reliable performance and longevity, particularly in environments where water exposure is likely. Furthermore, I incorporated a 10A relay module, It’s crucial to select the appropriate relay module based on the specifications of your motor. Choosing the correct module will guarantee compatibility and optimal functionality for your specific setup. Also, I used an LCD screen and four LEDs to display the water level and motor status. But, you can also see this data on the Blynk dashboard.

  • If you want to do this project with the ESP8266, please use this link.

OK, let’s do this project step by step. The required components are given below.

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, install the ESP32 board on the ESP32 adapter. If you don’t have an ESP32 adapter, please use two breadboards.

Step 3

Thirdly, place the LEDs one by one on the breadboard. And then, connect the resistors to the LED anode pins.

Step 4

Next, connect the LEDs to the ESP32 board. For that, use the circuit diagram below.

How to make a water level monitoring system with ESP32 board and Blynk

Step 5

Now, connect the LCD screen, ultrasonic sensor, and relay module to the ESP32 board. For that, use the circuit diagram above.

Step 6

Now, let’s set up the Blynk web dashboard step by step. For that, follow the instructions below.

  • First, go to the Blynk website and create a new account using your Gmail. And then, log in to your account and create a new template. I have created it as a “Water level monitoring system”.
  • Next, click the Detastrem tab and create two virtual pins. For that, use the instructions below.
  • Name — Water level / PIN — V0 / MIN — 0 / MAX — 13(Water tank height)
  • Name — Water pump / PIN — V1 / MIN — 0 / MAX — 1
  • And then, create a dashboard. I have used one button and one gauge for that. Next, click the gear wheel icons on the widgets and select the Data stream.
  • Now, click the search icon and create a new device. For that, select the template you created earlier.

OK, the Blynk web dashboard is ready for you.

Step 7

Now, connect the ESP32 board to the computer. Then, copy and paste the following program into your Arduino IDE.

//Include the library files
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

#define LED1 2
#define LED2 4
#define LED3 5
#define LED4 18
#define trig 12
#define echo 13
#define relay 14

//Enter your tank max value(CM)
int MaxLevel = 13;

int Level1 = (MaxLevel * 75) / 100;
int Level2 = (MaxLevel * 65) / 100;
int Level3 = (MaxLevel * 55) / 100;
int Level4 = (MaxLevel * 35) / 100;

//Initialize the LCD display
LiquidCrystal_I2C lcd(0x27, 16, 2);

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.init();
  lcd.backlight();
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
  pinMode(LED3, OUTPUT);
  pinMode(LED4, OUTPUT);
  pinMode(trig, OUTPUT);
  pinMode(echo, INPUT);
  pinMode(relay, OUTPUT);
  digitalWrite(relay, HIGH);
  
  lcd.setCursor(0, 0);
  lcd.print("System");
  lcd.setCursor(4, 1);
  lcd.print("Loading..");
  delay(4000);
  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);
  } 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);
  } 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);
  } else if (Level4 <= distance && Level3 > distance) {
    lcd.setCursor(8, 0);
    lcd.print("Full");
    lcd.print("      ");
    digitalWrite(LED1, HIGH);
    digitalWrite(LED2, HIGH);
    digitalWrite(LED3, HIGH);
    digitalWrite(LED4, HIGH);
  }
}

//Get the button value
BLYNK_WRITE(V1) {
  bool Relay = param.asInt();
  if (Relay == 1) {
    digitalWrite(relay, LOW);
    lcd.setCursor(0, 1);
    lcd.print("Motor is ON ");
  } else {
    digitalWrite(relay, HIGH);
    lcd.setCursor(0, 1);
    lcd.print("Motor is OFF");
  }
}

void loop() {
  ultrasonic();
  Blynk.run();//Run the Blynk library
}
  • Now, copy and paste the Blynk Auth token. And then, enter your WIFI name and password.
  • Next, select the board and port. After that, click the upload button. At this point, if you encounter an error uploading the program, press and hold the “boot” button for two seconds while uploading the program.
  • The process is successful. Now remove the USB cable.

Step 8

Now, let’s set up the Blynk mobile dashboard.

  • First, download and install the Blynk app on your smartphone. Then, log in to your account using your email and password.
  • Next, select the template you created on the web dashboard. After, add one button and one gauge to the dashboard. You can customize these widgets as you like.
  • Finally, click the widgets one by one and select the appropriate data stream as in the web dashboard. Also, you can change the color, text size, and other settings as you like.

OK, the Blynk mobile dashboard is ready for you.

Step 9

Now, connect the water pump to the relay module. I have used the small water pump for that. You can change it to your liking, but you must remember to use the appropriate relay module. Also, I used the two Li-ion batteries to power up this motor.

Step 10

Next, install the components as you like. For that, you can use the pictures below. Finally, provide an external 5VDC power supply to the ESP32 board.

Now, you can control this project using your smartphone or computer. The full video guide is below. We hope to see you in the next tutorial or project.

How to make a water level monitoring system with ESP32 board and Blynk

Similar Posts

Leave a Reply

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