How does a Water Level Sensor Work and How to Interface it with Arduino?

Published  April 18, 2022   0
Interfacing Water Level Sensor with Arduino

Water tank overflow is a common problem that results in water wastage, and it's surprising to note that it's not even considered a concern in many households. Though there are many solutions for it like ball valves that automatically cut the flow of water when a certain level is reached but as an electronic engineer, I prefer a solution that includes sensors and automation. So in this tutorial, we are going to interface a water level sensor with Arduino to measure the water level and in the process, we will let you know the details about this sensor and its working. So without further ado, let's get right into it.

Water Level Sensor Pinout

The working principle of the water level sensor module is very similar to that of a Rain Sensor.

The water level sensor has three pins, runs on 5V power, and gives out the data in analog format. The pinout of the water level sensor is given below: 

Water Level Sensor Pinout

VCC   is the power supply pin of the Rain Detection Sensor that can be connected to 5V of the supply.

GND   is the ground pin of the board and it should be connected to the ground pin of the Arduino.

OUT   is the Analog output pin of the board that will give us an analog signal in between VCC and ground.

How does a Water Level Sensor Work?

The working of the water level sensor is pretty simple and easy to understand. The PCB is made out of long conductive plates. When the water reaches a certain level the conductivity between the two plates changes, and by measuring the changes we can measure the water level.

Water Level Sensor Working

The above Gif shows the working of the water level sensor in action. As you can see when the drop of water falls inside the glass, the water level rises and the voltage on the output pin also rises. This phenomenon is directly proportional to the output voltage. This happens because the sensor portion on the PCB is made out of 10 conducting plates, 5 of which are power tracks and 5 others are the sensor tracks.

Water Level Sensor – Parts

This sensor is very simple, so it can be made with very few parts. This sensor produces the water level and outputs the data in an analog format. The parts marking of the sensor is shown below.

Water Level Sensor Parts

The sensor module has three pins, two of those are power pins and needs to be connected to the 5V and ground pin of the Arduino. As you can see in the above picture, the module has a single power LED that turns on when power is applied to the board, other than that we also have a transistor and a bunch of resistors that in total makes the water level sensor module.

Commonly Asked Questions about Water Level Sensor Module

What are the types of water level sensors?

There are six basic types of commercially used water level indicators: Resistive, Capacitive, Ultrasonic, Frequency, Guided wave GWR, and Pressure transducers. Each of these commonly used indicators have benefits, and each has its drawbacks.

What are level sensors used for?

Water level sensors detect the level of liquids and other fluids and fluidized solids, including slurries, granular materials, and powders that exhibit an upper free surface.

Is it possible to make a water level indicator at home?

If you can accrue all the basic supplies like LEDs, a buzzer, and sensing wires. Then it is not hard to build a basic water level indicator.

Can ultrasonic sensors detect water levels?

With ultrasonic sensors, we can find the water depth calculation by finding the distance between the transceiver and the surface of the water. The sensor will transmit a short ultrasonic pulse, and we can measure the travel time of that pulse (the echo) to the liquid and back.

Circuit Diagram for Water Level Sensor Module

The Schematic Diagram of the Water Level Sensor is shown below and as you can see it's pretty simple to understand.

Water Level Sensor Schematic

In the schematic, the collector of the transistor is connected to the supply voltage of 5V, and the emitter is connected to the ground with a 100 Ohms resistor. In the module, a set of 5 conducting plates are connected with the vcc in series with a 100 Ohms resistor and the other 5 sets are connected to the base of the NPN transistor. Now when the water touches these conducting palates, currents start flowing from the 5V supply to the base of the transistor, and the transistor turns on. The more submerged the sensor is, the more output voltage it will generate. 

Arduino Water Level Sensor Circuit  – Connection Diagram

Now that we completely understand how the water level sensor works, we can connect all the required wires to the Arduino UNO board, and in this section of the article, we will discuss just that!

Arduino Water Level Sensor Module Circuit Diagram

In the above figure, the connection diagram for the water level sensor with Arduino is shown. We have connected an LED to the PWM pin6 of the Arduino board and the analog output pin of the sensor is connected to the A0 pin. The ground pin is common in between the module and the LED, and the VCC is taken from the 5V pin of the Arduino. We will program the Arduino so that the brightness of the LED will change depending on the water level sensed by the sensor.

Water Level Sensor with Arduino UNO

Arduino Code for Interfacing Water Level Sensor Module with Arduino

The Arduino water level sensor code is explained below. The code is very simple and easy to understand. We just have to read the analog data out of the sensor and we can approximate the average water level with the ADC of the Arduino

We initialize our code by declaring two macros, the first one is for the LED, where we will connect an LED and the second one is the sensorPin through which we are reading the data coming out of the sensor. 

// Sensor pins pin D6 LED output, pin A0 analog Input
#define ledPin 6
#define sensorPin A0

Next, we have our setup() function. In the setup function, we initialize the serial with 9600 baud. We also set the ledPin as output, and make the pin LOW. This way the pin will not float and turn the LED on.

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

Next, we have our loop function; in the loop function we read the sensor pin and stored it in a local variable named sensorValue. Then, we defined an if condition in which we check if the incoming value from the sensor is greater than 570, if so, we map the value with the help of the inbuilt map function of the Arduino and finally, we generate the PWM signal with the help of analogWrite function, the final serial.print function is there for 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
  }
}

Working of the Arduino Water Level Sensor 

The gif down below shows the Water Level Sensor working. At first, you can see that the LED on the breadboard is off but when we put some water on the glass, the brightness of the LED starts to increase and when the water in the glass is full the LED glows at full brightness.

One problem we have encountered while working with this sensor is that the bottom portion of this sensor is very sensitive, while the top portion is not that sensitive. If the water level crosses the bottom portion, the sensitivity almost goes to maximum and it saturates.

Projects using Water Level Sensor Module

Previously, we have used this Water Level Sensor to build many interesting projects. If you want to know more about those topics, links are given below.

Simple Water Level Indicator Alarm with Buzzer
Simple Water Level Indicator Alarm with Buzzer

If you are a beginner and want to build your own jelly bean water level sensor, this project is for you because here we have used some general purpose transit, some resistor, LEDs, and a buzzer to build a simple water level sensor.

Measure Water Level using JSN SR-40T Waterproof Ultrasonic Sensor
Measure Water Level using JSN SR-40T Waterproof Ultrasonic Sensor

If you are thinking about building a simple yet effective water level sensor for day to day use, you can check out this project because in this project we have used an industrial-grade ultrasonic water level sensor to build a water level alarm which also shows the amount of water available in the tank.

Automatic Water Level Indicator and Controller using Arduino
Automatic Water Level Indicator and Controller using Arduino

If you are interested in building a simple water level sensor for home use this project can be for you, because in this project we have used an Arduino and some relays to build a simple water level display with an overflow alarm.

Supporting Files

Code

//Arduino water level sensor code

// Sensor pins pin D6 LED output, pin A0 analog Input

#define ledPin 6

#define sensorPin A0

void setup() {

  Serial.begin(9600);

  pinMode(ledPin, OUTPUT);

  digitalWrite(ledPin, LOW);

}

void loop()

{

  unsigned int sensorValue = analogRead(sensorPin);

  if (sensorValue < 540)

    return;

  uint8_t outputValue = map(sensorValue, 540, 800, 0, 255);

  Serial.print(sensorValue);

  Serial.print(" ");

  Serial.println(outputValue);

  analogWrite(ledPin, outputValue); // generate PWM signal

}

Have any question realated to this Article?

Ask Our Community Members