A smart, real-time solution for monitoring water levels remotely. Built with an ESP32 and an ultrasonic sensor, this project provides a reliable and cost-effective way to keep track of water levels in tanks, wells, or reservoirs from anywhere in the world.
In many residential and industrial settings, manual monitoring of water tanks is inefficient and prone to error, leading to potential water shortages or overflows. This project offers a definitive solution by automating the monitoring process. It leverages the power of the Internet of Things (IoT) to provide real-time data on water levels, accessible through a custom dashboard on your phone or web browser.
This system is perfect for:
- 🏡 Homeowners: Monitoring overhead or underground water tanks.
- 🌾 Farmers: Managing water levels in irrigation tanks.
- 🏭 Industries: Keeping track of liquid levels in storage containers.
- 💧 Communities: Monitoring water reservoirs for public supply.
- Real-Time Data: Get instant updates on the water level.
- Remote Accessibility: Monitor your system from anywhere via a cloud-based dashboard.
- Pump Control: Manually or automatically control the water pump.
- Alerts & Notifications: Configure custom email alerts for critical water levels.
- Data Visualization: Analyze historical data through charts and logs to understand consumption patterns.
- Low Cost & Open Source: Built with affordable hardware and fully customizable software.
The workflow is as follows:
- Input (Data Acquisition): An ultrasonic sensor placed above the water tank (
Tangki Air) continuously measures the distance to the water's surface. - Processing: An ESP32 microcontroller reads the raw data from the sensor. It then processes this data to calculate the current water level and percentage.
- Connectivity: The ESP32 connects to a local Wi-Fi network to gain internet access, acting as the bridge between the physical hardware and the cloud server.
- Backend & Frontend Server: The processed data is transmitted over the internet to the Web Server. This server hosts both the backend and frontend applications.
- The Backend is responsible for data storage, user authentication, pump control logic, and sending notifications.
- The Frontend provides a user-friendly dashboard for real-time monitoring and interaction.
- Output (User Interface): The end-user can access the web application from any device with a browser, such as a smartphone or PC. From the dashboard, the user can:
- View Real-time Monitoring data.
- Perform Pump Control.
- Receive Notifications about the tank's status.
- Review Data History.
- Microcontroller: ESP32 Development Board
- Sensor: HC-SR04 Ultrasonic Sensor
- Firmware: C++ on the Arduino Framework
- Backend: Node.js, Express, MongoDB, Mongoose, WebSocket (ws)
- Frontend: Next.js, React, Tailwind CSS
- Cloud Platform: Deployed on any platform that supports Node.js (e.g., Vercel, Heroku, AWS).
Follow these steps to set up the project.
- Hardware:
- ESP32 Development Board
- HC-SR04 Ultrasonic Sensor
- Jumper Wires
- 5V Power Supply (e.g., USB adapter)
- Software:
- Arduino IDE installed.
- ESP32 Board Core: Install the ESP32 board manager in your Arduino IDE. Follow this tutorial.
- Node.js (for the backend)
- MongoDB (or a MongoDB Atlas account)
Connect the components as described below. It is crucial to ensure all connections are secure for accurate readings.
| HC-SR04 Pin | ESP32 Pin |
|---|---|
VCC |
VIN |
GND |
GND |
Trig |
GPIO5 |
Echo |
GPIO18 |
⚠️ Important: The HC-SR04 sensor'sEchopin outputs a 5V signal, while the ESP32's GPIO pins are only 3.3V tolerant. For long-term reliability and to prevent damage to your ESP32, it is highly recommended to use a simple voltage divider (e.g., a 1kΩ and a 2kΩ resistor) to step down the 5V signal to approximately 3.3V before connecting it to the ESP32'sEchopin.
# Navigate to the backend directory
cd BackEnd
# Install dependencies
npm install
# Create a .env file and add your configuration
# (see .env.example)
cp .env.example .env
# Run the server
npm run dev# Navigate to the frontend directory
cd FrontEnd
# Install dependencies
npm install
# Run the development server
npm run dev-
Open in Arduino IDE: Open the
.inoproject file from theFirmwaredirectory. -
Configure Credentials: Update the Wi-Fi credentials and the server endpoint in the code.
// --- CONFIGURATION --- const char* ssid = "YOUR_WIFI_SSID"; const char* password = "YOUR_WIFI_PASSWORD"; const char* server_ip = "YOUR_BACKEND_SERVER_IP"; const int server_port = 8080; const int TANK_HEIGHT_CM = 200; // Total height of your tank // ---------------------
-
Upload the Code:
- Connect the ESP32 to your computer via USB.
- In the Arduino IDE, go to
Tools > Boardand select a generic board like "ESP32 Dev Module". - Choose the correct COM port under
Tools > Port. - Click the Upload button.
-
Monitor: Open the Serial Monitor (
Ctrl+Shift+M) at a baud rate of115200(ESP32's default) to see status messages and readings.
- No Data on Dashboard:
- Ensure the ESP32 is connected to your Wi-Fi (check the Serial Monitor in Arduino IDE for logs).
- Verify that the
server_ipin the firmware code is correct and accessible from your ESP32's network. - Check that the backend server is running and there are no firewall rules blocking the connection.
- Inaccurate Readings:
- Ensure the sensor is perfectly perpendicular to the water surface.
- Make sure the
TANK_HEIGHT_CMconstant in the code matches your tank's actual height. - Check your voltage divider resistors if the readings are consistently wrong.
- Automated Pump Control: Implement logic on the backend to automatically control the pump based on user-defined thresholds.
- Solar Power: Make the system self-sufficient by powering it with a solar panel and a rechargeable battery.
- Data Logging: Store data locally on an SD card as a backup in case of network failure.
- Enhanced UI: Develop a custom web application or mobile app for a more tailored user experience.
Contributions are what make the open-source community an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature) - Commit your Changes (
git commit -m 'Add some AmazingFeature') - Push to the Branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Distributed under the MIT License. See the LICENSE file for details.