In this article, we will make a device that will monitor liquid levels in water/oil or any tank. The monitored level information will be sent to a monitoring station. This can be helpful to monitor some water tanks installed at a place where humans cannot frequently reach and at places that are toxic, like labs where liquid chemicals are stored in large containers.
Components required
Tools Required/ libraries required
Arduino IDE
Arduino Library – Wi-Fi manager
Technical Insights
We will be using an IR distance measuring sensor to measure the level of liquid-filled in containers or tanks. The sensor’s output is measured in a unit and stored in a microcontroller; in this case, Arduino UNO. The sensor data is then sent using ESP to the thingspeak server for monitoring.
Block Diagram
IR sensor is connected to Arduino Uno and sending sensor data to it. The ESP is connected to the Arduino and Wi-Fi router, with a ThingSpeak library for communication purposes.
How the system works
- When powered on for the first time, the ESP generates a hotspot named “OilTank -1” displayed on an OLED display.
- We need to connect to it and open url http://192.168.4.1/ to set up the ESP.
- Then from the configuration panel, we can set which Wi-Fi ESP will connect to. We just enter the SSID and password of the Wi-Fi.
- After connecting to Wi-Fi, the name of Wi-Fi is displayed on the OLED screen.
- A battery also operates the device, so battery percentage is also shown on the screen and the tank’s liquid level.
- Now after connecting to the internet, the device sends data every 20 Seconds to the thingspeak server.
- If the Wi-Fi is disconnected, on the screen, you will see that Wi-Fi is disconnected, and ESP will generate a hotspot again.
Understanding the source code
To understand the code, there are two files; one is for ESP, and another is for Arduino.
ESP.ino
We are also using a Wi-Fi library for ESP to easily configure ESP using its hotspot without writing Wi-Fi information in the code. We are connected with thingspeak API when the internet is connected. The code is designed to send anything coming to serial, which is not a command for ESP to the thingspeak API dashboard.
So, let’s take a look at the code.
- In the setup function we are creating a hotspot using WiFi-Manger library
wifiManager.autoConnect(“OilTank-1”); - If the hotspot is created, ESP was not previously connected to Wi-Fi which is now available. The hotspot is a blocking loop for the program, so we send a “setup” command before creating a hotspot. That means the setup information will be displayed on the screen.
- If the hotspot is OFF the, we send the “conn” command, which means the ESP is connected to Wi-Fi, and the program follows.
Serial.print(“conn”); - ESP is also listening for some commands on which it replies to Arduino
- If none of those commands are recognized, then this data will be the tank level data which will be sent using the thingspeak library
ThingSpeak.writeField(myChannelNumber, 1, recivedData, myWriteAPIKey);
Arduino.ino
Arduino is installed with an OLED library to display the OLED data; it also communicates with ESP on serial communication.
Arduino code is also taking analog values from the sensor on analog pin A2 and calculates voltages. From there, we can map that to tank level.
The function tank_data() takes reading on analog pin 2 and then calculates the voltage reading and then send that to ESP in a period of 20 seconds.
val = analogRead(A2);
voltage = ((val * 3.3000) / 1024.0);
There are a few commands for OLED, which Arduino is receiving from ESP at serial.
This is how we can make a Liquid level monitoring system.
Board.ino source code:
ES.ino source code:
Video demo:
You may also like:
Filed Under: Applications, Electronic Projects, Featured, IoT applications
Questions related to this article?
👉Ask and discuss on Electro-Tech-Online.com and EDAboard.com forums.
Tell Us What You Think!!
You must be logged in to post a comment.