Meta Description: Learn how to build a smart river water level and pollution monitoring boat using ESP32, GPS and water quality sensors. Includes components, circuit connections, Arduino code and IoT monitoring.
1. Introduction
Water pollution is a major environmental challenge affecting rivers, lakes, dams and other natural water resources. Industrial waste, agricultural chemicals, sewage discharge and plastic pollution can negatively affect aquatic ecosystems and human health.
Traditional water quality monitoring often involves collecting water samples and transporting them to laboratories for testing. Although this method provides useful information, it can be time-consuming and may not provide continuous information about changing river conditions.
The Smart River Water Level and Pollution Monitoring Boat / Buoy Using ESP32 and GPS is an innovative IoT-based environmental monitoring project designed to address this challenge.
The system uses a floating boat or buoy equipped with water quality sensors to collect information about the surrounding water. An ESP32 microcontroller processes the sensor readings and uses a GPS module to determine the geographical location where measurements are collected.
The system can monitor several environmental parameters, including:
- Water temperature.
- Water turbidity (cloudiness).
- Water pH (acidity or alkalinity).
- Electrical conductivity (EC).
- Total Dissolved Solids (TDS).
- Geographical location using GPS.
The collected information can be transmitted to an online dashboard through Wi-Fi or a cellular communication module, allowing environmental researchers, students and water resource managers to monitor river conditions remotely.
2. Objectives of the Project
The main objectives are:
- To design a smart floating river monitoring boat using ESP32.
- To monitor water quality using electronic sensors.
- To measure water temperature, pH and turbidity.
- To estimate dissolved substances using a TDS sensor.
- To determine the geographical location of water samples using GPS.
- To transmit environmental data to an online monitoring dashboard.
- To identify possible changes in river water quality.
- To support environmental conservation and pollution monitoring.
3. How the Smart River Monitoring Boat Works
The project combines electronic sensors, a microcontroller, GPS technology and wireless communication.
The floating boat or buoy moves on the surface of the river while its water quality sensors collect measurements.
The ESP32 receives the sensor information and processes it into readable values.
The GPS module provides geographical coordinates, allowing each measurement to be associated with a particular location.
The system then transmits the collected information to an online dashboard for monitoring and analysis.
System operation
- The boat or buoy floats on the river surface.
- Water quality sensors collect environmental measurements.
- The ESP32 processes the sensor readings.
- The GPS module determines the monitoring location.
- The ESP32 combines the sensor readings with GPS coordinates.
- Data is transmitted through Wi-Fi or cellular communication.
- The online dashboard displays water quality information and location.
4. Components and Materials Required
The following components are required to construct the monitoring system.
| No. | Component | Quantity | Purpose |
|---|---|---|---|
| 1 | ESP32 DevKit | 1 | Main microcontroller |
| 2 | NEO-6M GPS module | 1 | Determines geographical location |
| 3 | Waterproof turbidity sensor | 1 | Measures water cloudiness |
| 4 | pH sensor module | 1 | Measures water acidity or alkalinity |
| 5 | DS18B20 waterproof temperature sensor | 1 | Measures water temperature |
| 6 | TDS sensor module | 1 | Estimates dissolved solids |
| 7 | Waterproof ultrasonic sensor | 1 | Optional river level measurement |
| 8 | 18650 rechargeable batteries | 2 or more | Power supply |
| 9 | Solar panel | 1 | Battery charging |
| 10 | GPS antenna | 1 | Improves GPS reception where required |
| 11 | Floating boat or buoy body | 1 | Supports the monitoring equipment |
| 12 | Waterproof enclosure | 1 | Protects electronics |
| 13 | Jumper wires | As needed | Electrical connections |
| 14 | Voltage regulator and charging circuit | 1 set | Power management |
Optional components include a GSM/4G module, LoRa communication module, OLED display and motor controller.
5. Understanding the Main Electronic Components
A. ESP32 Microcontroller
The ESP32 is the main processing unit. It receives information from the water quality sensors, processes the measurements and transmits data to an online dashboard.
B. NEO-6M GPS Module
The NEO-6M GPS determines the geographical coordinates of the monitoring boat. It provides latitude and longitude information that can be used to identify the location of possible pollution hotspots.
C. Turbidity Sensor
A turbidity sensor measures the cloudiness of water caused by suspended particles such as soil, sediment and other materials. Increased turbidity may indicate contamination or sediment disturbance.
D. pH Sensor
The pH sensor measures how acidic or alkaline the water is. The pH scale generally ranges from 0 to 14, with 7 representing neutral conditions at approximately 25°C.
E. DS18B20 Waterproof Temperature Sensor
This sensor measures water temperature. Temperature changes can affect aquatic organisms, dissolved oxygen and other water quality characteristics.
F. TDS Sensor
The Total Dissolved Solids sensor estimates the concentration of dissolved substances in water, commonly expressed in parts per million (ppm). It is useful for observing changes in dissolved ionic substances but cannot identify individual pollutants.
6. Circuit Diagram and ESP32 Connections
The ESP32 connects to the different sensors through its analogue input pins and digital communication interfaces.
The GPS module communicates with the ESP32 through UART, while the DS18B20 temperature sensor uses the OneWire communication protocol.
Pin connection table
The following pin arrangement can be used for the prototype.
| Component | Sensor pin | ESP32 pin |
|---|---|---|
| Turbidity sensor | Analog OUT | GPIO 34 |
| pH sensor | Analog OUT | GPIO 35 |
| TDS module | Analog OUT | GPIO 32 |
| DS18B20 | Data | GPIO 4 |
| GPS NEO-6M | TX | GPIO 16 (RX2) |
| GPS NEO-6M | RX | GPIO 17 (TX2) |
| Ultrasonic sensor | TRIG | GPIO 5 |
| Ultrasonic sensor | ECHO | GPIO 18 through voltage divider |
| DS18B20 | VCC | 3.3V |
| GPS module | VCC | According to module specification |
| All sensors | GND | Common GND |
Important electrical precautions:
- ESP32 analogue inputs must not receive voltages above 3.3V.
- Check the maximum output voltage of each analogue sensor module. Use suitable voltage dividers or signal-conditioning circuits where necessary.
- Install a 4.7 kΩ pull-up resistor between the DS18B20 data line and 3.3V.
- Check the GPS module’s logic-level requirements before connecting its RX pin.
- The HC-SR04 and similar 5V ultrasonic sensors require an Echo voltage divider.
- Use a regulated power supply for the ESP32 and sensors.
7. Step-by-Step Project Construction
Step 1: Prepare the floating boat or buoy
Construct a floating platform using waterproof plastic, PVC pipes or a suitable sealed container.
The structure should be stable enough to carry the electronics, sensors, battery and solar panel.
Step 2: Install the ESP32
Mount the ESP32 inside a waterproof electronics enclosure.
The enclosure should protect the controller from rain, splashing water and moisture.
Position the GPS antenna where it has a clear view of the sky. Avoid enclosing the antenna inside metal.
Step 3: Install the water quality sensors
Mount the pH, turbidity, TDS and temperature probes so that their sensing portions can contact the river water.
Ensure that:
- The pH electrode remains properly immersed when taking measurements.
- The turbidity sensor is positioned away from direct sunlight where possible.
- The TDS probe is immersed according to its manufacturer’s instructions.
- The temperature probe is exposed to the surrounding water.
Keep electronic circuit boards and sensor signal-conditioning modules dry.
Step 4: Connect the GPS module
Connect the NEO-6M GPS module to the ESP32 using the UART pins.
The GPS antenna should be positioned above the water and away from sources of electrical interference.
Step 5: Connect the power supply
Connect the rechargeable battery to a suitable regulated power management circuit.
A solar panel can be used to recharge the battery, allowing the monitoring platform to operate for longer periods.
Step 6: Connect the communication system
Configure the ESP32 to transmit the collected measurements to an online dashboard through Wi-Fi.
For river locations without Wi-Fi coverage, use a suitable cellular modem or LoRa communication system with an available gateway.
Step 7: Test the monitoring system
Place the boat or buoy in a controlled water container before deploying it in a river.
Check the temperature, pH, turbidity, TDS and GPS readings to ensure that all sensors are functioning correctly.
8. Arduino IDE Programming Code
The following example demonstrates how to collect sensor readings, obtain GPS coordinates and transmit the information to an online ThingSpeak dashboard.
Required Arduino libraries
Install these libraries using Arduino IDE Library Manager:
- TinyGPSPlus
- OneWire
- DallasTemperature
The ESP32 board package should also be installed in Arduino IDE.
ThingSpeak dashboard setup
- Visit ThingSpeak.
- Create an account.
- Create a new channel.
- Enable seven fields.
Use the following field arrangement:
| Field | Data |
|---|---|
| Field 1 | Water pH |
| Field 2 | Turbidity sensor voltage |
| Field 3 | TDS estimate |
| Field 4 | Water temperature |
| Field 5 | Latitude |
| Field 6 | Longitude |
| Field 7 | Water level (optional) |
Copy the channel’s Write API Key and insert it into the program.
ESP32 source code
#include <WiFi.h>
#include <HTTPClient.h>
#include <TinyGPSPlus.h>
#include <OneWire.h>
#include <DallasTemperature.h>
// Wi-Fi settings
const char* ssid = "YOUR_WIFI_NAME";
const char* password = "YOUR_WIFI_PASSWORD";
// ThingSpeak settings
String apiKey = "YOUR_WRITE_API_KEY";
// Sensor pins
#define TURBIDITY_PIN 34
#define PH_PIN 35
#define TDS_PIN 32
#define TEMP_PIN 4
// GPS pins
#define GPS_RX 16
#define GPS_TX 17
// Temperature sensor
OneWire oneWire(TEMP_PIN);
DallasTemperature tempSensor(&oneWire);
// GPS object
TinyGPSPlus gps;
HardwareSerial gpsSerial(2);
// Sensor readings
float phValue = 0;
float turbidityVoltage = 0;
float tdsValue = 0;
float temperature = 0;
double latitude = 0;
double longitude = 0;
void setup() {
Serial.begin(115200);
gpsSerial.begin(
9600,
SERIAL_8N1,
GPS_RX,
GPS_TX
);
tempSensor.begin();
WiFi.begin(ssid, password);
Serial.println("Connecting to Wi-Fi");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("\nWi-Fi Connected");
}
void readGPS() {
while (gpsSerial.available()) {
gps.encode(gpsSerial.read());
}
if (gps.location.isValid()) {
latitude = gps.location.lat();
longitude = gps.location.lng();
}
}
void readSensors() {
int rawPH = analogRead(PH_PIN);
int rawTurbidity = analogRead(TURBIDITY_PIN);
int rawTDS = analogRead(TDS_PIN);
// Convert ADC readings to voltage
float phVoltage = rawPH * 3.3 / 4095.0;
turbidityVoltage =
rawTurbidity * 3.3 / 4095.0;
float tdsVoltage =
rawTDS * 3.3 / 4095.0;
// Example only: requires pH calibration
phValue = 7.0 +
((2.5 - phVoltage) * 3.5);
// Example TDS estimation
// Requires calibration with standard solutions
tdsValue =
(133.42 * tdsVoltage *
tdsVoltage * tdsVoltage
- 255.86 * tdsVoltage *
tdsVoltage
+ 857.39 * tdsVoltage) * 0.5;
// Read water temperature
tempSensor.requestTemperatures();
temperature =
tempSensor.getTempCByIndex(0);
Serial.println("\n--- RIVER MONITOR ---");
Serial.print("pH: ");
Serial.println(phValue);
Serial.print("Turbidity Voltage: ");
Serial.println(turbidityVoltage);
Serial.print("TDS: ");
Serial.println(tdsValue);
Serial.print("Temperature: ");
Serial.println(temperature);
Serial.print("Latitude: ");
Serial.println(latitude, 6);
Serial.print("Longitude: ");
Serial.println(longitude, 6);
}
void uploadData() {
if (WiFi.status() == WL_CONNECTED) {
HTTPClient http;
String url =
"http://api.thingspeak.com/update?api_key="
+ apiKey;
url += "&field1=" + String(phValue, 2);
url += "&field2=" + String(turbidityVoltage, 3);
url += "&field3=" + String(tdsValue, 1);
url += "&field4=" + String(temperature, 2);
url += "&field5=" + String(latitude, 6);
url += "&field6=" + String(longitude, 6);
http.begin(url);
int response = http.GET();
Serial.print("Upload response: ");
Serial.println(response);
http.end();
}
}
void loop() {
readGPS();
readSensors();
uploadData();
delay(20000);
}
Important calibration note: The pH and TDS equations above are illustrative starting points, not universal sensor conversion formulas. Their accuracy depends on the particular sensor interface, ADC characteristics, calibration solutions and temperature compensation. Calibrate the pH probe using appropriate buffer solutions and the TDS module using known conductivity standards. The turbidity voltage is deliberately uploaded as a raw measurement because converting it into NTU requires sensor-specific calibration. Validate the GPS fix before accepting location data.
ThingSpeak commonly enforces a minimum 15-second update interval for free channels, so the example uses a 20-second delay. The example uses HTTP for simplicity; use HTTPS and appropriate certificate validation for a production deployment.
9. River Water Level Monitoring
In addition to water quality monitoring, the project can be upgraded to measure changes in river water levels.
There are two possible approaches.
A. Waterproof ultrasonic measurement
A waterproof ultrasonic sensor such as the JSN-SR04T can be mounted on a fixed bridge or riverbank structure facing the water surface.
It measures the distance between the sensor and the water surface.
The river level can then be calculated using:
L=H-d
Where:
- = Water level above the reference point.
- = Known distance from the sensor to the reference datum.
- = Measured distance to the water surface.
B. Water pressure sensor
A waterproof pressure transducer can be submerged at a fixed depth to measure the pressure exerted by the water.
The pressure measurement can be used to estimate water depth.
h=\frac{P}{\rho g}
Where:
- = Water depth.
- = Water pressure relative to atmospheric pressure.
- = Density of water.
- = Acceleration due to gravity.
Important design consideration: A floating buoy rises and falls with the river surface. Therefore, an ultrasonic sensor mounted on the buoy cannot independently measure absolute river-level changes. For reliable river-level monitoring, use a fixed reference on the riverbank or bridge, or a properly anchored pressure sensor.
The floating boat is best suited for mobile water quality measurements, while a fixed monitoring station provides more reliable river-level measurements.
10. IoT Dashboard and Remote Monitoring
The ESP32 can transmit collected data to ThingSpeak, where it can be displayed through charts and monitoring widgets.
The dashboard can display:
| Parameter | Information displayed |
|---|---|
| Water pH | Acidity or alkalinity |
| Turbidity | Water cloudiness |
| TDS | Estimated dissolved solids |
| Temperature | Water temperature in °C |
| Latitude | GPS geographical coordinate |
| Longitude | GPS geographical coordinate |
| Water level | River level from fixed monitoring station |
The GPS coordinates can also be opened in Google Maps to identify the monitoring location.
For example, the dashboard can help identify locations where turbidity increases or pH changes significantly.
11. Pollution Detection and Alert System
The project can be upgraded to identify unusual changes in water quality.
For example:
| Parameter | Possible observation |
|---|---|
| pH | Unusual acidic or alkaline conditions |
| Turbidity | Increased suspended particles |
| TDS | Changes in dissolved ionic substances |
| Temperature | Unusual temperature increases |
| GPS | Location of the recorded measurement |
An additional buzzer or notification system can be introduced to alert researchers when readings exceed selected monitoring thresholds.
However, these sensors do not identify specific chemicals, pathogens, heavy metals or all forms of pollution. They provide screening information that should be followed by laboratory analysis where contamination is suspected.
12. Power Supply and Solar Charging System
Since the monitoring boat may operate away from buildings and electrical outlets, a rechargeable battery system is recommended.
Suggested power components
| Component | Purpose |
|---|---|
| Solar panel | Converts sunlight into electrical energy |
| Rechargeable battery | Stores electrical energy |
| Solar charge controller | Manages battery charging |
| DC-DC converter | Provides regulated voltage |
| ESP32 | Processes and transmits information |
| Waterproof enclosure | Protects electronics |
The solar panel should be sized according to the total power consumption, operating time, battery capacity and expected sunlight.
Use a proper battery management system with overcharge, over-discharge and short-circuit protection. Do not connect a solar panel directly to a lithium battery.
13. Improving the Project Using Additional Technologies
The project can be further improved through the following developments.
A. Autonomous Navigation
Add DC motors, propellers, motor drivers and a suitable control system to allow the boat to move between selected monitoring locations.
B. LoRa Communication
Use LoRa modules to transmit sensor readings over longer distances where suitable gateway coverage is available.
C. GSM/4G Communication
Integrate a cellular modem to send monitoring data from remote river locations to an online platform.
D. Automatic Pollution Alerts
Configure the ESP32 to send notifications when measured parameters exceed predetermined thresholds.
E. Artificial Intelligence Integration
Historical measurements can be analysed to identify unusual changes, pollution patterns and possible environmental risks.
F. Water Sampling Mechanism
A small controlled pump can be added to collect water samples for laboratory testing at selected GPS locations.
14. Applications of the Smart River Monitoring System
The project has several potential applications.
- River pollution monitoring: Observing changes in river water quality.
- Environmental conservation: Supporting research into aquatic ecosystems.
- Agriculture: Monitoring water sources used for irrigation.
- Water resource management: Collecting geographical water quality data.
- Industrial monitoring: Observing downstream changes near industrial discharge locations.
- Research institutions: Supporting environmental science experiments.
- Flood monitoring: Combining fixed river-level sensors with GPS-enabled monitoring stations.
- STEM education: Demonstrating IoT, robotics, electronics and environmental science.
15. Advantages of the Project
- Supports continuous environmental data collection.
- Combines GPS location tracking with water quality monitoring.
- Can transmit information to remote dashboards.
- Reduces the need to manually collect every monitoring reading.
- Can identify locations requiring further environmental investigation.
- Supports solar-powered operation.
- Can be upgraded into an autonomous monitoring boat.
- Encourages practical innovation in environmental conservation.
16. Limitations and Troubleshooting
| Problem | Possible cause | Solution |
|---|---|---|
| GPS does not provide coordinates | Poor satellite reception | Position antenna with a clear sky view |
| Incorrect pH readings | Poor calibration | Calibrate using standard buffer solutions |
| Unstable turbidity readings | Sensor positioning or interference | Clean and reposition the probe |
| Incorrect TDS readings | Temperature or calibration error | Calibrate with conductivity standards |
| ESP32 disconnects | Weak Wi-Fi signal | Use cellular or LoRa communication |
| Battery drains quickly | High power consumption | Optimize sampling and transmission intervals |
| Water enters enclosure | Poor waterproof sealing | Use suitable waterproof housing and cable glands |
Safety precautions: Test the boat in a controlled environment before river deployment. Secure the electronics, battery and sensors against water ingress. Avoid deployment during floods or dangerous river conditions. The system should be recovered safely for cleaning, calibration and maintenance.
17. Conclusion
The Smart River Water Level and Pollution Monitoring Boat / Buoy Using ESP32 and GPS demonstrates how Internet of Things technology can be applied to environmental conservation and water resource management.
By combining water quality sensors, GPS positioning and wireless communication, the project provides a platform for collecting geographical water quality information from rivers and other water bodies.
The ESP32 processes measurements from the sensors while GPS identifies where the readings are collected. The information can then be transmitted to an online dashboard for analysis and environmental monitoring.
With additional improvements such as solar charging, autonomous navigation, LoRa communication and automatic water sampling, the project can be developed into an advanced environmental monitoring platform.







