<img height="1" width="1" src="https://www.facebook.com/tr?id=1640437302870650&amp;ev=PageView &amp;noscript=1">

Subscribe to Email Updates

bg-img11.jpg

Build a Tank Volume Reader in Under $30 using ESP32

Maria Hernandez
By Maria Hernandez
on July 5, 2017

The Internet of Things has brought a lot of formerly complex device applications into the homes of many craft brewers and wine makers. Applications with level sensors have been used for decades in large refineries, water treatment plants, and chemical plants. With sensor prices falling, now both industrial and DIY can monitor the volume of any tank, barrel, or canister.  

The sensors available on the open market can sense most anything and are classified accordingly. Sensor used for measuring humidity are termed humidity sensor, pressure called pressure sensor, distance are called position sensors, and so on. In a similar fashion, the sensor used for measurement of fluid levels is called a level sensor.

The level sensors are used to measure the level of the free-flowing substances. Such substances include liquids like water, oil, slurries, etc as well as solids in granular/powder form (solids which can flow). These substances tend to get settle in the container tanks due to gravity and maintain their level in rest state. 

In this guide you will learn how to build your own home-made level, temperature, and humidity sensor. Also included are instructions for you newly collected data to be utilized via Ubidots, an application enablement platform.

Requirements

  • Plastic protection case
  • Wires
  • Micro USB cable

Wiring and Casing 

The sensor HC-SR04 (Ultrasonic Sensor) works with 5V logic. Please, follow the table and diagram below to make the correct connections between the ESP32 and the ultrasonic sensor :

Please, follow the table below to make the correct connections between the ESP32 and the DHT11 sensor (Temperature and Humidity Sensor):

I built a small prototype with a scale-sized tank to shows the functions of the sensor, but a final prototype with it case should look like this:

As you can see the ultrasonic sensor should be at the top of the tank, so with it we're going to be able to measure the distance between the up part of the tank and the endpoint of the substance:

Place the temperature and humidity sensors to monitor environment.

To  program your connected device, connect with the Arduino IDE.

Before beginning with the ESP32, setup your board with the Arduino IDE. If you are not familiar with a board setup, please reference the article below and follow step-by-step until you've compiled the board: 

Once your board is compiled, install the libraries required to run the sensors: "PubSubClient" and "DHT:"

  1. Go to Sketch/Program -> Include Library -> Library Manager and install the PubSubClient library. To simply find the correct library, search PubSubClient within the search bar.  

2. Go to the library repository to download the DHT library. To download the library click the green button called "Clone or download" and select "Download ZIP".


3. Now, back in the Arduino IDE, click on Sketch -> Include Library -> Add .ZIP Library

4. Select the .ZIP file of DHT and then “Accept” or “Choose

If successful you will receive the message below in the Arduino IDE:

5. Close the Arduino IDE and open it again. The restart is required; please do not skip this step. 

Now it is time to start coding :)

Copy the code below and paste into the Arduino IDE.

Next, assign the parameters: Wi-Fi name and password, plus your unique Ubidots TOKEN. If you don't know how locate your Ubidots TOKEN, please reference this article below. 

Once you've pasted your code and assigned the appropriate wifi, verify in the Arduino IDE. To verify, in the top left corner of our Arduino IDE you will see the below icons. Choose the Check Mark icon to verify any code.

Once verified, you will receive a "Done compiling" message in the Arduino IDE.

Next, upload the code into your ESP32. Choose the right-arrow icon beside the check mark icon to upload.

Once uploaded, you'll receive a "Done uploading" message in the Arduino IDE.

With this,  you're sensor is now sending the data to the Ubidots Could!

Management of the data in Ubidots 

If your device is correctly connected you will see a new device created within your device section in your Ubidots application. The name of the device will be "esp32", also inside the device you will see the variables distance, humidity, and temperature:

If you desire to change you device and variable names to a more friendly one, please reference this article:

Next, to calculate the volume of free-flowing substances in the tank, we need to create a derived variable to calculate a volume value. 

The Derived Variable let us build operations using the default variables, so in this case we are going to apply the volume formula with the characteristic of a cylindrical tank where:

  • Pi = The ratio of a circle's circumference to its diameter (constant)
  • r = The radius of the tank 
  • h = The height of the tank

 

Click on "Add variable" and select "Derived":

As you can see at the new window you have to attach the formula in the following field:

Once you've attached the formula with the characteristics of your tank, select the variable "distance."

With your formula entered, you're volume will begin reading in your Ubidots application.

Results

Now your sensor is ready to start working! Below you can see the function of the level sensor at different volumes:

To learn more about Ubidots widgets and events, check out these video tutorials.

Happy hacking :)

Leave a comment

Maria Hernandez
Written by Maria Hernandez
Written by Author

Related posts

Connect your ESP8266 to any available Wi-Fi network
Connect your ESP8266 to any available Wi-Fi network
Maria Hernandez
By Maria Hernandez
on July 5, 2017

The ESP8266 is a microcontroller developed by Espressif  Systems. Known as a WiFi Module, this microcontroller has the ability...