Table of contents
This project is one more version of a tank water level monitor. The water monitoring system is a liquid level measurement system to keep the user alerted in case of liquid overflow or when the tank runs out. An ultrasonic sensor will be fixed, which will be placed on the tank pointing at the liquid. The ultrasonic sensor is used to measure, compare the depth of the container and the liquid level. System status can be monitored via an LCD display and a buzzer sounds when the limit exceeds the allowable fill amount or falls below a set limit. Through the button we can silence the alarms with a long press and also turn on the LCD backlight for better vision with a short press.
You can view the demo here.
Warning : Once inside of WOKWI web press the PLAY button to start the simulation. Click on the ultrasonic sensor and a slider will appear to simulate the reading values of the sensor. Vary the values between 25 and 104 cm to see the tank fill animation. Where 25 cm is a full tank and 104 cm (tank height) is totally empty. The JSN-SR04T sensor has a dead zone of 25 cm.
- 24/7 tank level monitoring
- Avoid spillage of water due to overflow
- Prevent the tank from being empty and leaving the house without a water supply
.8. 8 8888 8888888 8888888888
.888. 8 8888 8 8888
:88888. 8 8888 8 8888
. `88888. 8 8888 8 8888
.8. `88888. 8 8888 8 8888
.8`8. `88888. 8 8888 8 8888
.8' `8. `88888. 8 8888 8 8888
.8' `8. `88888. 8 8888 8 8888
.888888888. `88888. 8 8888 8 8888
.8' `8. `88888. 8 888888888888 8 8888
For this project I used an Arduino nano due to its small size, to which a sensor and actuators will be connected. To display the information, a 20x4 LCD display was chosen with enough space to draw an animation of the tank filling. A buzzer for notification and a button for control.For a longer life of the ultrasonic sensor, the JSN-SR04T was chosen, which is waterproof. If you do not have this sensor and use another, make sure to protect it against moisture.
The Arduino(Hardware) components required are:
- Arduino Nano
- LCD screen 20x4
- A button
- A buzzer
- A 10k resistor
- A waterproof ultrasonic sensor JSN-SR04T
Below is the connection diagram and a table with the pins to be connected.
ARDUINO PINS | LCD PINS |
---|---|
12- D12 |
15 - A |
11- D11 |
4 - RS |
10- D10 |
6 - E |
9- D9 |
11 - D4 |
8- D8 |
12 - D5 |
7- D7 |
13 - D6 |
6- D6 |
14 - D7 |
GND | 16 - K |
GND | 1 - VSS |
VCC(5v) | 2 - VDD |
ARDUINO PINS | BUTTON PINS |
3- D3 |
1 - 3 |
GND | 2 - 4 |
ARDUINO PINS | BUZZER PINS |
4- D4 |
+ |
GND | - |
ARDUINO PINS | JSN-SR04T |
2- D2 |
TRIGGER |
3- D5 |
ECHO |
VCC(5v) | VCC |
GND | GND |
Warning : From pin 1-3 of the button connect a 10k resistor to VCC (5v).
👉 You can find the diagram here. ⭐
The code consists of a local library called Tank that is in charge of drawing the tank on the screen. Only a global LiquidCrystal library was used for display management. If you have a screen with I2C, you should replace this library with LiquidCrystal_I2C and initialize it in a different way than it is in the project, keeping the name as lcd. The rest of the libraries are for handling alarms, alarm tones, tank filling animation, measurement filter, code debugging and font. To activate the debugger, the code should look like this:
#define DEBUGLEVEL DEBUGLEVEL_DEBUGGING
//#define DEBUGLEVEL DEBUGLEVEL_NONE
You can vary the debugging level if you wish, by referring to the debug.h library and choosing the level you need. Button, Sensor, and Draw objects are created. The Button object handles the control of the button, which is used to silence high and low level alarms and turn on the screen backlight. The sensor object returns the distance measured by the ultrasonic sensor to be used in the calculation of the volume and the level of the liquid column in percent. Finally the draw object will draw each of the 8 possible glyphs that can be used to generate the tank fill animation.
The ultrasonic sensor measures the amount of empty space in the tank, that is, the distance between it and the water contained in the tank. Therefore, if we know the height of the empty tank (H), by subtracting the distance (D) from empty space we will know the height of the liquid column (C) that it has. Look at the figure below.
To calculate the volume of the tank, its measurements must be taken into account; they are entered as constants in the code.
Warning : It should be noted that the tank for which this code was created is atypical. It is a rectangular tank that has a partition in the middle and makes it 2 tanks. Due to this particular, the volume of the partition up to the height of the liquid column is also calculated to be later subtracted from the general volume and as a result the actual volume of liquid in the tank.
If you want to use this code to calculate the volume of liquid in your tank, you must modify the parts of the code that calculate volume that are in the get_volume function. You only have to take into account if your tank is cylindrical or rectangular and use the corresponding formula. I leave this link to a website for calculating the volume of tanks.
The most important constants to keep in mind are:
#define DIST_TOPE //height of the tank in cm measured with the tank empty.
const int NIVEL_BAJO //low percentage level from which the alarm is activated
const int NIVEL ALTO //high percentage level from which the alarm is activated.
The height of the tank should not exceed the maximum distance that your ultrasonic sensor can measure. Set a low level according to your tank fill needs. The high level is usually defined as close to 100%.
Warning : Even if the high level is defined as 100% and this level is reached, this does not mean that your tank will overflow. The waterproof ultrasonic sensor has a 25 cm measurement dead zone in which readings are unreliable. This is taken into account in the code so 100% would be the height of the tank minus 25 cm of dead range. This would be taking into account that the sensor is positioned at the height of the tank. If it is set higher be careful to define the high level for the alarm. See figure below.
Make a universal version of the project that includes the following features.
For the software part:
- Include a menu to configure ALL possible variables.
- Tank type. For an accurate calculation of the volume of water.
- Cylindrical or rectangular.
- Tank dimensions. The height of the tank can be entered both manually and automatically.
- Level to activate the alarm for low and high.
- Choice of the working mode of the device.
- Manual the user makes the decisions.
- Automatic when reaching the low level of the tank, the level in the cistern will be measured, if it is sufficient, the pump will be activated and the tank will be filled.
- Choice of alarm tone.
- Include the incoming water flow to be displayed on the screen.
- Choice of information to display on the screen.
- Tank type. For an accurate calculation of the volume of water.
For the hardware part:
- Being able to use different screens.
- LCD.
- OLED
- Increase the number of buttons to 3, for easy menu navigation.
- Add relay module to control the tank filling pump.
- Add a flow sensor to protect the filling pump and account for the amounts of water entering the tank.
- Add a second ultrasonic sensor to measure the level of the reservoir and that the filling is automatic when the low level is reached.
- And finally, if time is enough for me, I can make a version with esp32 that includes an embedded website and do all the control from your mobile.
Alexminator | 20-EverGreen-2 |
---|---|
The ALT project is released under the MIT license.
Need help? Feel free to contact me 📨 alexminator99@gmail.com
- VSCODE -A source code editor.
- PlatFormio - Open programming IDE for C/C++, hardware oriented.
- To the Cuban Arduino community.
- To everyone who gave me his help when I had doubts, especially my son.