Interfacing Water Level Sensor With Arduino

by Rithik0 in Circuits > Arduino

266 Views, 1 Favorites, 0 Comments

Interfacing Water Level Sensor With Arduino

IMG_7650.jpeg
water-level-sensor-assembled-image.jpg

Water tank overflow is a common problem leading to water wastage, often overlooked in many households. While ball valves can help, as an electronic engineer, I prefer a sensor-based solution. In this tutorial, we'll interface a water level sensor with Arduino to measure water levels and explain the sensor's workings. Let's dive in and tackle this watery issue with some tech magic!

Supplies

Arduino Water Level Sensor

Arduino UNO

Bread Board

LEDs

Jumper Wires

Water Container for Testing

Circuit Diagram for Interfacing Water Level Sensor With Arduino

connection-of-water-level-sensor-with-arduino.jpg

In the diagram, we connect an LED to the PWM pin 6 of the Arduino board. The sensor's analog output pin connects to the A0 pin. The ground pin is shared between the module and the LED, with VCC taken from the Arduino's 5V pin. We'll program the Arduino to adjust the LED brightness based on the water level detected by the sensor.


Assembling the Circuit

water-level-sensor-assembled-image.jpg

Let's get those wires connected and see it in action!


Arduino Code for Interfacing Water Level Sensor Module

Here's the simplified and easy-to-understand Arduino code for our water level sensor project. We'll read the analog data from the sensor and use the Arduino's ADC to estimate the water level.

First, we declare two macros: one for the LED pin and one for the sensor pin.

// Sensor pins: pin D6 for LED output, pin A0 for analog input

#define ledPin 6

#define sensorPin A0

In the setup function, we initialize the serial communication at 9600 baud, set the LED pin as output, and ensure it's turned off initially.

void setup() {
 Serial.begin(9600);
 pinMode(ledPin, OUTPUT);
 digitalWrite(ledPin, LOW);
}

In the loop function, we read the sensor value, store it in `sensorValue`, and check if it exceeds 570. If it does, we map this value and use it to generate a PWM signal to control the LED brightness. The `Serial.print` function helps with debugging.

void loop() {
 int sensorValue = analogRead(sensorPin);
 if (sensorValue > 570) {
  int outputValue = map(sensorValue, 570, 800, 0, 255);
  Serial.println(outputValue);
  analogWrite(ledPin, outputValue); // generate PWM signal
 }
}


And there you have it—simple, effective, and ready to light up your water tank monitoring game!

Working of the Arduino Water Level Sensor

The GIF below demonstrates the Water Level Sensor in action. Initially, the LED on the breadboard is off. As water is added to the glass, the LED's brightness increases, and when the glass is full, the LED glows at full brightness.

One issue we encountered is that the bottom portion of the sensor is very sensitive, while the top portion is not as responsive. Once the water level crosses the bottom portion, the sensitivity peaks and quickly saturates.

Downloads

Conclusion

In this project, we've demonstrated how to build a basic water level detection system using an Arduino and a water level sensor. By interfacing the sensor with the Arduino, we can measure water levels and control an LED to indicate the water level in a tank. This project highlights the practical application of sensors and microcontrollers in everyday tasks, promoting efficient water management and preventing wastage.


However, we did encounter a sensitivity issue with the sensor: the bottom portion is extremely sensitive, while the top portion is less so. This can cause the sensor to saturate quickly once the water level reaches a certain point.


For a more detailed explanation of this project, including the schematic and working principles of the water level sensor, please refer to our official page  How does a Water Level Sensor Work and How to Interface it with Arduino? . Additionally, check out our extended project that uses three LEDs to demonstrate the sensor's functionality more comprehensively.


Dive into our resources to explore more exciting DIY projects and enhance your understanding of sensor-based automation!