Contents

Make a Liquid Level Indicator with Arduino

Overview

 In this tutorial, you’ll get to know about liquids level detection with Arduino. First, you’ll see some information about the water level sensor, and then you’ll learn how to use this module with some practical examples.

What You Will Learn

What Is Water Level Detection?

Liquid level detection or in other words, measuring the level of liquid in deep tanks or water in reservoirs is done in order to control the depth of water and prevent it from the overflow in industry. In household applications also it can be used for example to detect the water level inside aquariums. The purpose of the level measurement is to determine the level of liquid at any moment and do the required operation accordingly.  There are different ways to measure the liquid level. Some sensors calculate the depth of liquid according to the pressure caused by the liquid’s specific gravity and the vertical distance to the surface. Some others emit ultrasonic waves from a transducer which also detects and measures the reflected waves to calculate the liquid depth.  The sensor that we use in this tutorial is Arduino compatible and works on the basis of resistance measurements, you’ll soon find out how it works. 

How Water Level Sensor Works

This module, which is one of the most widely used modules for detecting the liquid level, works on the basis of resistance change. On this module, there are parallel lines of conductivity that are connected to the Ground and are in fact the path of electric current. Water is a good conductor so when these lines are in the water, they will be short circuit, and the resistance of the module decreases. 

By fixing the module on the liquid container, the variable resistance sets on a specific value based on the water level. As the water level increases, the resistance of the connected copper path will decrease, therefore more current flows through the circuit (in practice, the sensor acts like a variable resistor). With this method, the sensor can measure the water level.

The output of this sensor is analog voltage. The higher the liquid level, the higher the output voltage.

Water Level Sensor Pinout

This sensor has 3 pins:

  • +: Module power supply – 2-5 V
  •  -: Ground
  •  S: Analog output

You can see pinout of this module in the image below.

Required Materials

Hardware Components

Arduino UNO R3 × 1
Liquid Level Detection Sensor Module × 1
YwRobot Water Level Sensor Module × 1
Waveshare Liquid Level Sensor × 1
Jumpers × 1
Buzzer × 1

Software Apps

Arduino IDE

Interfacing Water Level Sensor with Arduino

You don’t need any specific library to use this sensor. Just read the analog value of the output pin and calculate the liquid level accordingly. 

Step 1: Circuit

The following circuit shows how you should connect Arduino to water level sensor. Connect wires accordingly.

Step 2: Code

Upload the following code on your Arduino board and open the serial monitor window. Place the sensor in water, and you can see the results on your serial monitor window.

/* Water level sensor
 *  by Hanie Kiani
 *  https://electropeak.com/learn/   
 */
const int analogInPin = A0; 
int sensorValue = 0;

void setup() {
 Serial.begin(9600); 
}
 
void loop() {
 sensorValue = analogRead(analogInPin); 
 Serial.print("Sensor = " ); 
 Serial.print(sensorValue*100/1024); 
 Serial.println("%");
 delay(1000); 
}

Use the Liquid Level Sensor as a Rain Detector

You can also use the water level sensor to detect rain with a buzzer. To detect whether it is raining, position the sensor horizontally so that raindrops can fall on the sensor and increase the value of the pin S. 

When the sensor starts getting wet, the buzzer will start beeping every few seconds. And when the module becomes completely wet, the buzzer warns with louder sound and will continue beeping nonstop. 

Step 1: Circuit

Step 2: Code

/* 
   * Rain Detector with Water level sensor
 *  by Hanie kiani
 *  https://electropeak.com/learn/   
 */
const int sensorMin = 0;     // sensor minimum
const int sensorMax = 1024;  // sensor maximum
const int buzzer = 9;
void setup() {
  Serial.begin(9600);  
  pinMode(buzzer, OUTPUT);
}
void loop() {
int sensorReading = analogRead(A0);
int range = map(sensorReading, sensorMin, sensorMax, 0, 3);
  // range value:
  switch (range) {
 case 0:    // Sensor is wet
    Serial.println("ٌWet!");
    tone(buzzer, 5000); 
    break;
 case 1:    // Sensor getting wet
    Serial.println(" Warning");
     tone(buzzer, 1000 , 5); 
    break;
 case 2:    // Sensor dry 
    Serial.println("Dry");
    noTone(buzzer);  
    break;
  }
  delay(10);  // delay between reads
} 
The map() function divides the sensor range 0 to 1024 into 3 sections.
 tone(buzzer, 5000);
The tone() function sends a PWM signal on the buzzer pin so the buzzer will make a sound. The first argument specifies the output pin, and the second one determines the PWM frequency. It can also have a third argument standing for the signal duration.

What’s Next?

  • Try to use the SMS module (like the Sim800 module) with your rain detector, so that it can inform you the raining by sending a message on your phone.
Liked What You See?​
Get Updates And Learn From The Best​

Comments (2)

  • Syafika Reply

    Can I know the unit of the analogue value from the water level sensor output?

    July 15, 2021 at 5:13 am
    • Mehran Maleki Reply

      It’s just an analog value in volts that has an direct relationship with the liquid level. The higher the liquid level, the greater the output value.

      July 17, 2021 at 7:10 am

Leave a Reply

Your email address will not be published. Required fields are marked *