Summers are back and with the season of increased water shortage in urban areas, comes the increased responsibility of reducing water consumption an wastage. The increase in global temperatures makes it ever so important to reduce this problem of water wastage.
With the available technology, it must be an easy problem to solve, isn't it? It certainly is. In the era of electronics and IoT, its become even easier to automate the task.
In this tutorial we will learn how to use water-level indicator module with an Arduino UNO. In upcoming tutorials we will add a relay and a Wi-Fi module so we can control a motor and read real time water values on our phones.
You will need:
Know your sensor:
Any water level sensor works on the basic principle that water conducts electricity. Current is flowing through the many metal strips on the sensor. When water comes in contact with these metal strips, it conducts electricity and the metal strips can 'sense' water. The specific sensor we are using in this project is an analog sensor. Pretty basic electronics, huh?
Let's get Started!
STEP 1: Connect Everything
First connect the Water Level Sensors to the Arduino UNO. You will notice there are three pins on the sensor. Use the table below to make the connection using Female to Male Jumper wires directly to the Arduino or through a breadboard. Since this sensor is analog we connect the S pin to A5 in on the Arduino.
SENSOR |
ARDUINO |
Ground (-) |
GND |
VCC 5v (+) |
5V |
Data Pin (S) |
A5 |
STEP 2: Fire up Arduino IDE and let’s get coding
Arduino IDE is used to program your Arduino Board. If you don’t have it downloaded already you can download and install this from https://www.arduino.cc/en/main/software
When done, open up the IDE and connect your Arduino to your computer's USB port with the provided cable.
After the basic initialization we can get started. The sensor spits out data from 0 – 1024, which shows the level of water. In the code below we show you how to read these values from the sensor and print it on your computer screen. If the code below does not work, check your connections again.
CODE:
void setup()
{
Serial.begin(9600); //start a serial monitor on 9600 baud rate
}
void loop()
{ //loop to print repeated values
Serial.print("Water level Sensor Value:");//message
Serial.println(analogRead(A5)); //reading value from sensor
delay(100); //delay to print every 100 miliseconds
}
You can find the above code in the .ino file below!
https://github.com/thinkobotics/TUTORIALS/tree/master/waterlevel_tutorial
STEP 3: Test your set up
After performing the steps 1 and 2 above, open your serial monitor and you should see some values running around. You will notice that if there is no water the value is always 000. Next, try dipping the sensor in a glass of water. Now the magic happens! You will see the values change depending on how deep you submerge your sensor in water.
Hope you had fun performing this small project. In the next tutorial we will connect a Relay Module and use it to turn a water pump on or off depending on the water level.
Stay tuned!