How to Build a Simple Arduino Water Level Indicator with Buzzer Alarm
Introduction
I want to build a simple water level indicator that can detect the water level in a tank or container and sound an alarm if the water reaches a preset high or low level. This project will use an Arduino microcontroller board along with a few basic electronic components.
The main components I will need are:
- An Arduino Uno board
- A breadboard
- A buzzer
- A 10K ohm resistor
- A photocell sensor
- Jumper wires
- A 9V battery and clip
The circuit will work by using the photocell sensor to detect the presence or absence of water at a specific height. The photocell sensor works by changing resistance depending on the amount of light hitting it. When placed at the desired water level in the tank, the sensor will detect when the water level reaches that point and trigger the buzzer alarm.
The Arduino will monitor the sensor input and control the buzzer. It will sound the alarm when the preset water level is reached.
How a Photocell Water Level Sensor Works
A photocell, also known as a photoresistor, is a light-controlled variable resistor. It works by changing resistance depending on the amount of light hitting the sensor.
When the photocell is in the dark, its resistance is very high, often up to 1M ohm. When light hits the sensor, the resistance decreases dramatically, down to a few hundred ohms.
I can use this variable resistance to detect the presence of water. By placing the photocell at a specific height on the side of a water tank, it will normally be hit with ambient light, meaning its resistance will be low. But when the water level rises up and submerges the sensor, blocking ambient light, the resistance will increase drastically.
This change in resistance is detected by the Arduino, allowing it to sense when the water level has hit the height of the sensor. I just need to preset a threshold value in the Arduino code to trigger the alarm.
Circuit Diagram
Here is the circuit diagram showing how to connect the components:
The photocell sensor is connected in series with a 10K resistor between 5V and ground. This creates a voltage divider, allowing the Arduino to measure the changing voltage depending on the photocell's resistance.
The buzzer is connected to Arduino pin 8 through a 220 ohm resistor. This resistor protects the buzzer from excessive current.
Setting up the Sensor
To position the photocell sensor, I will:
-
Measure the height at which I want to detect water level.
-
Mount the photocell at that height on the side of the tank using tape or glue. Make sure no external light hits the sensor directly.
-
The sensor should point inwards towards the inside of the tank.
-
For detecting multiple water levels, mount multiple sensors at different heights along the tank.
-
Run wires from the sensors to the breadboard.
The key is positioning the sensor so it is exposed to ambient light when water is below it, but blocked from light when the water level rises over it. This triggers the change in resistance.
Arduino Code
The Arduino code will do the following main tasks:
-
Read the analogue voltage value from the sensor input pin.
-
Compare this to a preset threshold value that indicates the water is at the sensor level.
-
Trigger the buzzer alarm when water level is detected.
-
Monitor the sensor continually in a loop.
Here is simple code to achieve this:
```
const int sensorPin = A0; // Photocell connected to analogue pin A0
const int buzzer = 8; // Buzzer connected to digital pin 8
int sensorValue = 0; // Variable to store sensor value
void setup() {
pinMode(buzzer, OUTPUT); // Set buzzer as output
}
void loop() {
sensorValue = analogRead(sensorPin); // Read analogue voltage from sensor
// Check if over threshold
if(sensorValue > 400) {
tone(buzzer, 1000); // Sound buzzer if sensor triggered
} else {
noTone(buzzer); // Turn off buzzer if below threshold
}
delay(10); // Small delay
}
```
The code is fairly simple. The key points are:
-
Read the analog voltage from the sensor input pin A0
-
Check if over a threshold (e.g. 400) to detect water presence
-
Turn on the buzzer at pin 8 by using the tone() function
-
Else turn off the buzzer with noTone()
-
Loop continually to monitor water level
The buzzer will sound an alarm when water is detected. The threshold of 400 was chosen as an example and can be adjusted as needed.
Testing the Sensor
Once everything is wired up, the code can be uploaded to the Arduino board.
To test the water level sensor:
-
Place the sensor in air and open the serial monitor. The voltage should read around 400-1023 when no water is present.
-
Place a cup of water below the sensor, covering it completely. The voltage should drop down below 400 once it is submerged.
-
Adjust the threshold in the code if needed to fine tune the detection.
-
Check that the buzzer properly turns on once the sensor is submerged in water.
Once tuned correctly, the sensor will work reliably to detect water and sound the alarm automatically at the desired water level.
Conclusion
This simple Arduino based water level indicator provides an easy way to monitor tank water levels and sound an alarm when needed.
The photocell sensor along with Arduino input monitoring allows reliable and customizable water detection. With multiple sensors, several water levels can be monitored.
The buzzer alarm brings instant indication when the tank water reaches concerning levels. This type of automated indicator has many useful applications in irrigation, water storage systems, aquariums and more.
Some ways to expand this project include adding an LCD display to show the current water level, incorporating a float switch for analog water level readout, or connecting the alarm to the internet for text or email alerts.
I hope you found this water level indicator project useful! Let me know if you have any other questions.