Building an Arduino Water Level Detection Sensor

by Van3ss4 in Circuits > Sensors

13814 Views, 147 Favorites, 0 Comments

Building an Arduino Water Level Detection Sensor

Bild1.png

There are many different ways to measure the water level. It can be easily done with an ultrasonic sensor but there are also these red sensor modules for the arduino that are specifically designed to measure water levels.

In this instructable we're going to build one ourselves and learn how they work.

Supplies

  • 3d printer
  • Arduino Uno
  • 0,8 mm wire
  • Jumper Cables
  • Resistors
  • Soldering Iron
  • Multimeter
  • Computer and Cable to connect to the Arduino

How It Works

Spannungsteiler.png
Water-Level-Sensor-Working.gif
Bild1.png

First we need to understand how the sensor works.

As you can see there are several parallel copper tracks on the pcb. Those are alternately connected to VCC and GND. While the sensor is dry there is no electrical connection between them but as the water level is rising they get connected. We can treat them as a variable resistor.

The higher the water level rises, the lower drops the resistance.

The resistance can be measured using a voltage divider as shown in the picture above. It's a really simple circuit with R1 beeing a fixed resistor and R2 beeing our variable resistor. Since the current through all resistors in a row is the same, the voltage drop at every resistor is dependent on it's resistance - or it's proportion of the total resistance of the circuit. So as the water level increases, the voltage measured at 'Analog In' increases until the whole sensor is covered in water.

With the total height of the sensor as well as the max and min values at 'Analog In', we can calculate the water level.

Building the Measuring Grid

PXL_20210715_101942528.MP.jpg
PXL_20210715_103134477.MP.jpg
PXL_20210715_103448095.MP.jpg

First, print out the attached file. It's 10 cm long.

Then push the wire trough the holes on the side like shown in the picture, cut it off and repeat the process for all the other holes. Always let a few cm sticking out alternately on the left and right side. We need that to solder the wire together.

Now bend the sticking out wire like shown in the 2nd picture and solder the ends together. Now solder one jumper cable on each end.

Measure the Resistance

PXL_20210715_104015091.MP.jpg

Measure the resistance of the grid using a multimeter, while it's still dry.

Depending on that value, choose your fixated resistor - it's value should be somewhere in the same range as the one of your grid. My grid for eample has a resistance of a few Million ohms, so I chose a 1M ohm resistor.

Build Your Circuit and Upload the Code

Screenshot 2021-07-19 144212.png
Screenshot 2021-07-19 140845.png

Now build the circuit on a breadboard (note: the editor for the picture had no water level sensor, so I inserted a photodiode instead - just connect the jumpercables from the grid) and upload the attached code to the arduino.

To dial it in, uncomment line 25 'Serial.println(sensorVal);'

Now open the Serial Monitor (on the top right of the Arduino IDE) and see what values get printed. The Analog Input of the Arduino takes voltages from 0 - 5 V and converts them to values from 0 - 1024. Because our selfmade sensor is connected directly to the Arduino and has no circuit to stabilize the values, they propably are going to be pretty unstable.

Your upper limit should be approximately the value that you can read from the Serial Monitor. In my case it's somewhere around 550. Change the variable 'upperLimit' to that value.

Now put the sensor completely in water and see how the serial output changes. Change the variable 'lowerLimit' to the value you see in the Serial Monitor.

Note that in order to get a rather reliable output, it's beneficial to have a larger difference between your upper and lower limits. If they are really close together, already a small value change due to drifting or unstability will change the output by a lot. You want the upper and lower limit to be a few hundret digit apart.
To increase the difference, try different resistor values for your fixed resistor. The smaller you make it, the higher the sensor values should get. Always check the Serial Monitor to see how the values change and if they're in a useful range

You can now comment out line 25 again to only see the measuring result.

Testing

Testing My Selfmade Water Level Detection Sensor (Arduino)

Now we're done. You can take a glass and fill it with water to test if the sensor works properly. If it doesn't, go back to the previous step and repeat the calibration process. If you pull the sensor out of the water there are still some drops on the holding grid, so the upper value might be different than when the sensor was completely dry beforehand.

Note that the sensor is rather innacurate with about +/-1 cm because it has no stabilization circuit.
It can also happen that it won't work with a different kind of water as the conductivity of water is heavily dependent on what's in it (minerals, dirt and so on). You might need to dial it in again or build a circuit that solves that problem using e.g. a transistor.