IoT-based Water level indicator with ESP32

IoT Based Water Level Indicator using Ultrasonic Sensor

Make IoT-based Water Level indicator using Ultrasonic sensor, ESP32, OLED, & Blynk. Get LOW Water Level notification. (Circuit + Code + PCB)

In this IoT internet of this project, I have explained how to make a simple IoT-based water level indicator using an ultrasonic sensor, ESP32, and Blynk IoT platform.

The alarm will start for the LOW water level, and you will get a Blynk notification on the smartphone through the internet. Also, you can monitor the water tank level on OLED.

IoT-based water level indicator

The alarm will also start when the tank is full. You press the push button to stop the alarm.

So if you follow all the steps, you can easily make this IoT based water level monitoring system using ESP32 and Blynk app.

Required Components for ESP32 Water Level Sensor

Required Components for ESP32 Water Level Sensor
  • ESP32 DEV KIT V1
  • SR04M waterproof ultrasonic sensor OR HC-SR04 sensor
  • 0.96″ I2C OLED Display
  • 220-ohm 0.25watt Resistors – 2 no
  • BC547 NPN Transistor
  • LED 5mm – 1no
  • 2-pin Push Button
  • 2-pin Terminal connectors (3 no)
  • 5V DC Buzzer
  • AC to DC converter PM01 5V (Optional)

Circuit of IoT Based Water Level Indicator

Water Level Indicator circuit
using SR04M-2 waterproof ultrasonic sensor

In the circuit, if you want to use AC voltage, then you have to use a PM01 AC to DC converter. Otherwise you can directly give 5V DC supply to this circuit.

The GPIO D26 & D27 are connected with Echo & TREG pin of the SR04M-2 waterproof ultrasonic sensor.

The OLED SDA & SCL pins are connected with D21 & D22 GPIO of ESP32.

GPIO D12 is connected with the push button to stop the buzzer. I have used the INPUT_PULLUP function in Arduino IDE instead of using the pull-up resistors with the push button.

And the indicator LED and Buzzer are connected with GPIO D14 & D13 of ESP32.

You can use any other ultrasonic sensor.

Water Level Indicator circuit
using HC-SR04 ultrasonic sensor

The minimum distance between sensor and full tank water level must be greater than 25cm.

PCB Layout for Water Level Indicator

Please download the PCB layout, then print it on the A4 page.

Please check the PCB size while printing, it should be the same as mentioned in Layout.

Homemade PCB for the Water Level Indicator

Water Level Indicator on Zero PCB

In the tutorial video, I have explained, how you can eassily make the complete circuit on zero PCB using the the PCB Layout.

Tutorial video on ESP32 Water Level Detector

  • During the tutorial video on wireless water level sensor, I covered the following topics:
  • Quick demo on IoT based water level monitoring system.
  • How to make the water level detector on Zero PCB.
  • Set up the Blynk IoT Cloud for ESP32.
  • Steps to add a device in Blynk IoT Cloud.
  • Source code for the IoT-based water level sensor.
  • Set up the Blynk IoT app to monitor the water level.
  • Add automation for LOW water level notification.

Set up Blynk IoT Cloud for the IoT-based Project

You can refer to the following article to set up the new Blynk cloud account

Getting started with New Blynk 2.0 IoT platform

  • Create Blynk Template

    During creating the template, I selected ESP32 as the hardware and the connection type as WiFi.

  • Create Datastreams in Blynk Cloud

    water level sensor Blynk datastreams

    In the template, I have created first Datastreams (Pin: V1, Datatype: Integer, Min Value: 0, Max Value: 100) to show the water level in tank in percentage.

    Second Datastream (Pin: V2, Datatype: String) will show the distance between sensor and water level in cm.

  • Add Automation in Blynk IoT

    water level sensor Blynk automation

    I have added Automation to get the LOW water Level notification in the Blynk IoT app.

    I have turned on the Condition and Action radio button for the first Datastream V1. Type of Automation will be “Sensor”.

  • Create Web Dashboard in Blynk Cloud

    water level sensor esp32 P18

    After that, click and drag 1 Gauge widgets, and 1 Level widget, and select the related Datastreams for each widget.

    Then click on “Save” to save the template.

  • Add Device in Blynk Cloud using Template

    You can refer to the following article to add a device to the Blynk cloud.

    Add Device in Blynk Cloud from Template

PCB for this ESP32 Water Level Indicator

You can also download the PCB Gerber file and order the PCB from PCBWay.

water level indicator circuit P19

About PCBWay and their services

You can order any custom design PCBs from PCBWay at very reasonable prices.

This image has an empty alt attribute; its file name is PCBWay-750x161-Banner.jpg

PCBWay not only produces FR-4 and Aluminum boards but also advanced PCBs like Rogers, HDI, and Flexible and Rigid-Flex boards, at very affordable prices.
For the online instant quote page please visit – pcbway.com/orderonline

You can also explore different PCB projects from their Open-source community pcbway.com/project/.

For more details please visit the following articles.
Why PCBway

Program ESP32 with Arduino IDE

For this IoT-based home automation project, I have used the Arduino IDE to program ESP32.

First update the Preferences –> Aditional boards Manager URLs: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_dev_index.json, http://arduino.esp8266.com/stable/package_esp8266com_index.json

  • Then install the ESP32 board (2.0.5) from the Board manager or Click Here to download the ESP32 board.
  • Download the required libraries from the following links:

Source Codes for Blynk ESP32 Water Level Sensor

Click on the following buttons to download the source codes for this ESP32 project.

In the sketch, you have to update only the BLYNK_TEMPLATE_ID, BLYNK_DEVICE_NAME, Auth Token.

/* Fill-in your Template ID (only if using Blynk.Cloud) */
#define BLYNK_TEMPLATE_ID ""
#define BLYNK_DEVICE_NAME ""
#define BLYNK_AUTH_TOKEN ""

Enter the WiFi Credentials.

// Set password to "" for open networks.
char ssid[] = "";
char pass[] = "";

Define Water Level Distance for empty tank and full tank in CM.

int emptyTankDistance = 70 ;  //Distance when tank is empty
int fullTankDistance =  30 ;  //Distance when tank is full
Water Level Distance for empty tank and full tank

Define trigger value in percentage, alarm will start when water level drop below triggerPer.

//Set trigger value in percentage
int triggerPer =   10 ; 

Here I have defined the triggerPer 10%, but you can define any value like 5%, 20% etc.

LOW Water Level trigger

The ESP32 will only calculate the water level if the measured distance is between empty tank distance and full tank distance.

After doing these changes, please upload the code to ESP32.

Install the Water Level Sensor circuit

Water Level Indicator PCB connection

On the PCB, either you can give AC supply as per the above circuit or you can give 5V DC supply as per the following circuit.

Water Level Indicator PCB connection 5V DC

***While fiting the ultrasonic sensor in the water tank, please make sure the minimum distance between sensor and full tank water level must be greater than 25cm.

I hope you like this IoT-based water level monitoring system using ESP32 and Blynk IoT app.

Click Here for more such ESP32 projects.

Please do share your feedback on this IoT project. Thank you for your time.

Leave a Reply

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