Arduino Program for Water Level
Monitoring
This project will use a water level sensor to detect water levels and display the results on the
Serial Monitor. We can extend this to trigger alarms, control pumps, or display readings on an
LCD.
🛠️ Required Components
1. Arduino Uno (R3)
2. Water Level Sensor
3. Jumper Wires
4. Breadboard (Optional)
5. Buzzer (Optional, for alerts)
🔌 Circuit Connections
Water Sensor Pin Arduino Pin
VCC (Power) 5V
GND (Ground) GND
A0 (Analog Output) A0
(A0 outputs an analog value that changes based on water level.)
📜 Arduino Code
#define WATER_SENSOR_PIN A0 // Define the analog pin for water sensor
void setup() {
Serial.begin(9600); // Start Serial Monitor
Serial.println("Water Level Monitoring Started");
}
void loop() {
int waterLevel = analogRead(WATER_SENSOR_PIN); // Read analog value from
the sensor
Serial.print("Water Level: ");
Serial.println(waterLevel); // Print the sensor value
// Define water level conditions
if (waterLevel < 200) {
Serial.println("Water Level LOW! ⚠️");
}
else if (waterLevel >= 200 && waterLevel < 500) {
Serial.println("Water Level MEDIUM 🟡");
}
else {
Serial.println("Water Level HIGH! 🚰");
}
Serial.println("-------------------");
delay(2000); // Wait 2 seconds before next reading
}
📖 Code Explanation
1️⃣ Define Sensor Pin
cpp
CopyEdit
#define WATER_SENSOR_PIN A0
We define A0 as the pin where the water sensor is connected.
2️⃣ Setup Function
cpp
CopyEdit
void setup() {
Serial.begin(9600);
Serial.println("Water Level Monitoring Started");
}
Start Serial Communication at 9600 baud.
Print a startup message.
3️⃣ Loop Function
cpp
CopyEdit
int waterLevel = analogRead(WATER_SENSOR_PIN);
Read the sensor value from A0.
The sensor outputs higher values when water level is high.
4️⃣ Display Water Level
cpp
CopyEdit
Serial.print("Water Level: ");
Serial.println(waterLevel);
Print the water level value on the Serial Monitor.
5️⃣ Set Water Level Conditions
cpp
CopyEdit
if (waterLevel < 200) {
Serial.println("Water Level LOW! ⚠️");
}
else if (waterLevel >= 200 && waterLevel < 500) {
Serial.println("Water Level MEDIUM 🟡");
}
else {
Serial.println("Water Level HIGH! 🚰");
}
LOW (Below 200): Water is low.
MEDIUM (200-500): Water is at a moderate level.
HIGH (Above 500): Water is at a high level.
6️⃣ Delay for Stability
cpp
CopyEdit
delay(2000);
Wait 2 seconds before the next reading.
📟 Output on Serial Monitor
1. Upload the Code to Arduino.
2. Open Serial Monitor (Baud Rate: 9600).
3. You will see:
markdown
CopyEdit
Water Level: 150
Water Level LOW! ⚠️
-------------------
Water Level: 350
Water Level MEDIUM 🟡
-------------------
Water Level: 700
Water Level HIGH! 🚰