To create an IoT-based water tank level measurement system with ESP32 Arduino, VL53L0X ToF sensor, PHP MySQL backend, and a web interface for visualization and real-time updates, we’ll need to divide the project into two parts: the Arduino sketch for data collection and the web interface for visualization and alerts. This article is slightly complex and it requires a basic knowledge to handle a LAMP server and may need some debugging, and error correction for your system.
The Web Interface For Data Storage & Visualization
Although you can use a shared server, it is probably better to use some cheap VPS and install the web server components:
For development purposes, can install the LAMP server on Ubuntu with one command: apt get install lamp-server^. However, you have to run the MySQL secure installation script manually (shown here How To Install MariaDB on Ubuntu 22.04).
---
Create a MySQL database and create a Table with the name water_level with the number of column 1. Name the column as level. The type will be INT. Length/Value will be 11, incremental and primary. You can run SQL queries to create it. This is important since you can not do anything without it.
You need a PHP script where you’ll insert data from ESP32 over the internet. Below is an example PHP script. You need to edit it to enter the database details. You can save this script as store_data.php:
You will need another script to retrieve data from the MySQL database. You can save it as get_data.php:
Naturally, you’ll need an HTML file with Ajax function to display this data, you can name it index.html:
The webpage automatically updates the water level every 5 seconds, providing real-time monitoring. To implement alerts for low water levels, additional JavaScript logic can be added to compare the current water level with a predefined threshold and trigger notifications accordingly.
ESP32 Sketch For Data Collection & Sending
You’ll get the basic information how to hookup VL53L0X ToF sensor with ESP32 in this article Water Tank Level Monitoring Using Laser ToF Sensor.
- Connect Vin to the power supply.
- Connect GND to common power/data ground.
- Connect the SCL pin to the I2C clock SCL pin on your Arduino (On a UNO this is A5). The hardware I2C clock SCL pin for the ESP32 is GPIO 22.
- Connect the SDA pin to the I2C data SDA pin on your Arduino (On a UNO this is digital 20). For ESP32, the SDA pin is GPIO 21.
In ESP32, you can set almost any pin as I2C via software. That is required to add multiple sensors. The VL53L0X has a default I2C address of 0x29. The connection will be like this diagram:

The illustration is from wolles-elektronikkiste.de/en/ for a different project
This is the ESP32 Arduino sketch:
I have kept all the files as a GitHub repository here.
Conclusion
This article shows you the logic to build a basic IoT-based laser water tank level monitor with ESP32, VL53L0X, PHP & MySQL. You can connect the VL53L0X sensor with ESP32 via CAT 4 cable. Ensure that the sensor is 90 degrees with the water level.
This project is too basic, may need error correction, there is no security, and there is no graphical presentation but at this moment you’ll not find so simple project on GitHub to achieve the goal.
By combining ESP32 Arduino, VL53L0X sensor, PHP MySQL backend, and a web interface, we’ve created an IoT-based water tank level measurement system capable of real-time monitoring. This solution can be further customized and expanded to suit specific requirements and integrate additional features for enhanced functionality and usability.