The tutorial for the project is based on wastage of water due to overflow and wastage of electricity. This happens because of the dry running of the pump in overhead water storage tanks. Hence, we would use Arduino Uno to resolve this problem by building a water tank monitoring system. Let’s understand the significance of this project before building it.
Most of the people in residential areas face the problem of running out of water. Additionally, the overflow of water in tanks is because of an excess supply of water. It becomes difficult for users to judge the level of water in water tanks. When the pump is on, users may not realize the level of water, which may result in an overflow.
A tank monitoring system can sort out the issues associated with a water tank. Thus, it is also possible to check the level of the water using a sensor so that whenever the water goes low, the pump turns on automatically. Also, to avoid the overflow of water, it detects when the water level goes above the set limit, which turns off the pump automatically.
Components for Water Tank Monitoring System
The following components are required to perform the application:
- Arduino Uno R3 board
- Ultrasonic sensor
- Relay board
- 16×2 LCD display with I2C interface
- 240 V AC submersible pump
- Connecting wires
The Arduino Uno R3 board comes with sets of digital and analog input/output (I/O) pins. These feature PWM, RXT, TXD, GPIO, and I2C pin activities. There are a total of 14 digital pins and 6 analog pins on the Arduino Uno R3 board.
Relays are used to control power appliances like lights, fans, etc. directly from microcontrollers or low voltage circuits. Here we used a four-channel relay board that operates on 5V to control a 240V pump. The relay can handle a maximum of 10A/250V AC or 10A/30V DC. The relay board has three high-power connections: Common (COM), Normally Open (NO), and Normally Closed (NC) with 5V VCC, GND, and control pins.
A 16×2 LCD is a very basic module for various devices and display applications. These modules are better than seven-segment and other multi-segment LEDs because they are economical and easy to program for characters and graphics. A 16×2 LCD means it can display 16 characters per line, and two such lines are giving us a considerate space to display our data.
The water level in the tank is continuously monitored by the ultrasonic sensor mounted on top. As the water level in the tank drops below 20 percent, the pump is turned on using the relay mechanism and is kept on until the tank is full. The pump is then turned off and the loop iterated again.
This tutorial focuses on implementing an Arduino-based system to monitor the water level in a tank using an ultrasonic sensor, which also controls a relay-connected pump based on the input from the sensor.
After gathering the required components, it’s time to implement a circuit following the circuit diagram.
Two water levels are set based on the total tank height. The lower level is at 20 percent of the total height, and the upper level is set at 90 percent of the total tank height.
The ultrasonic sensor is mounted on the top of the tank. When the tank is 20 percent full, the distance between the U.S. and the water surface will be:
h20%= Total height – height of 20% filled water
Similarly, when the tank is 90 percent full, the distance between the U.S. and the water surface will be:
h90%= Total height – height of 90% filled water
When the distance of the water surface from the ultrasonic sensor is greater than h20%, the pump is on. The pump is kept on until the set upper water level is achieved, then it automatically turns off. This happens when the distance of the water surface from the ultrasonic sensor is less than h90%.
Connecting the Components
Connect a buzzer to pin 10 of the Arduino board and ground its other terminal. The ultrasonic sensor’s Echo and Trigger pins are connected to pins 12 and 13 of the Arduino board respectively.
Now, connect pin 11 of the Arduino to the input pin of the relay board. Connect the pump to the AC circuit of the relay board. Tip: treat the relay board as a switch and complete the AC circuit.
The LCD module, equipped with an I2C interface can be connected by using only two analog pins, which in this case are connected to the A4 and A5 pins of the Arduino board. Now, provide the +Vcc and GND connections to the ultrasonic sensor, relay board, and LCD module using +5V and GND from Arduino.
Arduino IDE Setup
Install the Arduino integrated development environment (IDE) software on your PC, then connect the Arduino board to the PC using the USB cable. Set the board as “Arduino UNO” and port to whichever board is connected in the “Tools” menu of the IDE. You can find the port number by going to the “Device Manager” window on your Windows PC.
Code for Water Tank Monitoring System
Now, create a new sketch and write the following code. You can try to write your own code while keeping in mind which task the microcontroller should do based on a particular input.
Verify and Upload
Now you need to verify the code by pressing the verify button on the Arduino IDE toolbar. Wait for the code to verify. Once verified, you can see a “Done compiling” message on the screen.
If no errors were found, upload the code using the upload button beside the verify button. Wait for the code to get uploaded for the circuit to start working. You will also see a “Done uploading” message on the screen.
Code Explanation for Water Tank Monitoring System Using Arduino Uno
Firstly, all the required libraries are imported by the header files. The variables and pins are declared in the next step. The display characters for the bar graph are also defined here.
The void setup function runs once, initializing all the required pins on the Arduino board.
LCD module’s backlight is initialized here. LCD prints “Tank Monitor System” with a buzzer beep.
The void loop function runs the code repeatedly. First, the ultrasonic sensor sends an ultrasonic wave, which is reflected back from the water surface. The Arduino board calculates the time interval between sending and receiving the wave and converts it into the distance which is then stored in the distance variable.
Now, based on the distance value, the percentage of water level in the tank is calculated and also displayed on the LCD module. The
else condition statement after that is executed for different cases of water levels, and accordingly, a signal is sent to the relay board for turning the pump on or off.
Making an IoT-based tank monitor system gives real-time information about the current water level in the tank and also automates the process of filling the water tank, thus saving electricity and water. An Arduino UNO board is the brain of the system, which takes input from the ultrasonic sensor, processes it and displays it on an LCD module, and also controls the pump via a relay board accordingly.