How to Use the Water Level Sensor - Arduino Tutorial

About: Arduino Tutorials by 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.

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!



    • Safe and Secure Challenge

      Safe and Secure Challenge
    • Cardboard Challenge

      Cardboard Challenge
    • Epilog X Contest

      Epilog X Contest

    12 Discussions


    Question 6 months ago

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


    Question 9 months 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



    Question 9 months 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?


    11 months 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.


    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() {

    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.print("Water level: ");
    Serial.println(" mm");




    1 year ago

    Hi! what exact sensor is this


    1 year 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

    2 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

    Reply 1 year 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).


    2 years ago

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


    2 years ago

    Thankyou, that helped.