In this video, we're going to cover how to
use the water level sensor with the Arduino.
The water level sensor will help you easily
detect the presence of water and a relative
idea of its depth.
To use the water level sensor we need to wire
up the device to the Arduino.
It's very simple and only has three wires.
Plus 5 volts, ground, and the signal pin.
In this tutorial video we're going to show
our depth onto an LCD screen.
However, on the TheGeekPub.com there will
also be code for showing it on the serial
console.
First things first let's connect the water
level sensor to the Arduino.
We've already connected the LCD, but if you
want to learn how to wire them up we have
another video and article on that you can
check out.
Connect the sensor's ground pin to the ground
on your Arduino, or breadboard.
Connect the sensor's +5V to the 5 volt rail
on the breadboard or to the Arduino 5V pin.
Connect the signal pin to any of the analog
input pins on the Arduino.
We're going to use A5.
Alright let's move along to the code side
of things.
Detecting the water level is actually very
easy, and in this first set of code all we're
doing is reading the value from the A5 analog
input pin and then writing a water level value
to the serial console.
This code is great for just learning how the
senor works.
However, we're going to ramp it up by using
an LCD character display to show the water
level in real time.
This just requires adding the LCD character
display library and a couple extra lines of
code to refresh the cursor location on each
check of the water level sensor.
You can get both sets of the code at TheGeekPub.com.
Let's walk through the code.
At the top we're just including the LCD library
and then creating the LCD display by defining
which pins it will be using.
In the setup function we start the LCD process,
and write the static content to the first
line of the display.
In the loop function, we start by setting
the cursor to the first character of the second
row and then we read the current value of
the sensor via the A5 input pin.
After we have the sensor's value we check
it against different ranges to determine the
water level and then print the water level
on the display.
Finally, we wait one second before repeating
the cycle.
One note, you may need to adjust these ranges
based on the level of impurities in your water
supply.
See the article in the description for more
info on that.
Test your sensor by dunking it in a cup of
water.
You should see the depth level appear on your
LCD screen!
You can see all the impurities in my water
by how bad the mineral deposits are on this
glass.
There are many uses for this sensor.
My favorite is detecting if the water heater
is leaking by looking for moisture in its
drain pan, which should always be empty.
It can also be used in vacant vacation homes
to detect water near toilets or under sinks.
Well I hope you enjoyed this project.
If you did, do me a favor and tap that like
button and subscribe to my channel!
You can also consider supporting me on Patreon
at the link below.
