How to Use the Water Level Sensor - Arduino Tutorial

126,090

75

17

About: Arduino Tutorials by Codebender.cc Team

In this tutorial you will learn how to use a water level sensor with the Arduino uno board.

This module is designed mainly for the DIY hobbyist and provide them a low-cost and easy-to-use water level detection scheme. The sensor that I will use for this tutorial can measure water level up to 40mm (4cm).

This is an analog sensor and the data that we will read will be values from 0 to 1024.

Let's get started and find out more about it.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: What You Will Need

For this project you will need:

  • Arduino uno
  • Breadboard
  • Water Level Sensor

Step 2: The Circuit

The connections are pretty easy!

  • Vcc - Arduino 5V
  • GND - Arduino GND
  • A0 - Arduino Analog pin 0

Step 3: Find Analog Values

We need to find analog values for our sensor.

Upload the following sketch on Arduino by pressing the "Run on Arduino" button and then press the "Connect" button to start serial communication.

Now take a glass of water and slowly put in it the sensor.

My analog values from this procedure are:

  • 0mm - 480
  • 5mm - 530
  • 10mm - 615
  • 15mm - 660
  • 20mm - 680
  • 25mm - 690
  • 30mm - 700
  • 35mm - 705
  • 40mm - 710

As you can see the sensor resolution decreases as the water reaches the maximum level.

On next step we will map those values to print on serial monitor the level of water on mm.

Step 4: The Code

Here's the code, embedded using codebender!

Upload the following sketch on Arduino by pressing the "Run on Arduino" button and then press the "Connect" button to start serial communication.

You can keep playing with that by clicking the "Edit" button and start making your own modifications to the code. For example try to change the delay time.


Step 5: Well Done!

You have successfully completed one more Arduino "How to" tutorial and you learned how to use the water level sensor.

I hope you liked this, let me know in the comments.

There will be more of them, so make sure to click Follow button!

Be the First to Share

    Recommendations

    • Assistive Tech Contest

      Assistive Tech Contest
    • Reuse Contest

      Reuse Contest
    • Made with Math Contest

      Made with Math Contest

    17 Discussions

    0
    None
    SatyaD4

    9 hours ago

    Hi Sir Good Afternoon i am trying to interface the water level sensor using Arduino nano for harvesting the fish Aquarium automatic water level detecting and filling the water below average of water but, the tank depth was 45CM the sensor size only the 5 cm how to apply the same application using long height sensor OR if any chance to increase the size of sensor please reply this question sir thank you

    link: http://bigbelectronics.in/product.php?product=rain-water-sensor-liquid-level-sensor-module-depth-of-detection-arduino

    0
    None
    ShankarB11

    9 days ago

    Hi Sir Good Afternoon i am trying to interface the water level sensor using Arduino nano for harvesting the fish Aquarium automatic water level detecting and filling the water below average of water but, the tank depth was 45CM the sensor size only the 5 cm how to apply the same application using long height sensor OR if any chance to increase the size of sensor please reply this question sir thank you
    http://bigbelectronics.in/product.php?product=rain-water-sensor-liquid-level-sensor-module-depth-of-detection-arduino

    0
    None
    gusandfluffy

    Question 4 months ago on Step 5

    Does anyone know if the temperature of the water can effect the functionality, or the accuracy of an arduino water sensor? Also, can the device be fully submerged and still remain functional? Thanks!

    0
    None
    Eldin96

    Question 6 months ago on Step 3

    I have done everything same and on serial monitor the value is just decreasing until 374. Sensor is not in the water. What did i do wrong ? thank you

    0
    None
    GergelyO2

    1 year ago

    You can calculate exact mm values with the following code.

    A 4th degree polynomial fit approximates your calibration data with adj R-square over 0.99.

    The equation is:

    f(x) = p1*x^4 + p2*x^3 + p3*x^2 + p4*x + p5
    where x is normalized by mean 641.1 and std 83.32
    Coefficients (with 95% confidence bounds):
    p1 = 4.428 (1.955, 6.902)
    p2 = 16.17 (10.57, 21.76)
    p3 = 15.35 (12.44, 18.27)
    p4 = 7.229 (2.881, 11.58)
    p5 = 11.59 (9.973, 13.2)

    Different sensors need different coefficients or even different fit (cubic poly, exponential, power, etc.), but in your case these values are correct.

    CODE:

    const float p1 = 4.428;
    const float p2 = 16.17;
    const float p3 = 15.35;
    const float p4 = 7.229;
    const float p5 = 11.59;

    void setup() {
    Serial.begin(9600);
    }

    void loop() {

    int a = analogRead(A0);

    float b = (a - 641.1)/83.3;

    float w = (p1*pow(b,4)+p2*pow(b,3)+p3*pow(b,2)+p4*b+p5);

    if (a <= 480){
    Serial.println("Water level: 0mm - Empty!");
    }

    else if (a > 710){
    Serial.println("Water level: FULL");
    }

    else {
    Serial.print("ADC: ");
    Serial.println(a);
    Serial.print("Water level: ");
    Serial.print(w);
    Serial.println(" mm");
    }

    delay(5000);


    }

    1 reply
    0
    None
    FermionNGergelyO2

    Reply 8 months ago

    Hi GergelyO2,
    Could you please provide the source of this information (the polynomial equation)
    Thanks in advance.

    0
    None
    acrtsh

    Question 1 year ago

    hey, i'm using this sensor to my project, but anyone know kow much the accuracy value of this sensor?

    0
    None
    AdrianaE8

    Question 1 year ago

    Hi... I'm using this kind of sensor to measure the water that is transfered from one small gobele to another, for a future project.

    1º Question: I like to know if your Arduino values for each "mm" of the sensor were always so accurate as you say in step 3. Becausa my values fluctuate a lot.

    2ºQuestion: I like to know if i can use de code that you put in the comments below to calculate the exact "mm" values

    Thank

    0
    None
    MaynardG

    Question 1 year ago on Step 4

    Can I adapt this technique to indicate the water level in a 5,000 gallon water tank, 64" diameter, horizontal cylinder?

    0
    None
    rdemeter

    2 years ago

    Hi! what exact sensor is this

    0
    None
    yussufbn

    2 years ago

    pls i need ypur help on my project. which is "automated poultry feed and water supply" am using water level sensor and pressure load sensor

    1 reply
    0
    None
    licheong

    3 years ago

    Thanks! I'm trying to measure the water level on my balcony, but I wonder if there's any risk of short circuit if the water spills over the top. Is there any way to make the top part of the sensor water-proof?

    1 reply
    0
    None
    Waylon194licheong

    Reply 2 years ago

    I know this post is very old but I just wanted to give an answer.

    You have 2 options:

    1. Add heat shrink to the top of the sensor, this will prevent rain from getting on the board but it does NOT make it waterproof.

    2. Add hot glue/silicon sealing(I am not sure if you can use any type of sealent).

    0
    None
    Patrick_74

    3 years ago

    Can we use that sensor with gasoline, glow fuel nitromethane?

    0
    None
    Hooikraal

    3 years ago

    Thankyou, that helped.