Water Tank Levels by WiFi on Your Phone




Introduction: Water Tank Levels by WiFi on Your Phone

About: I'm retired, living in Queensland Australia with my wife. These are my hobbies, pretty much full time now. Isn't it great to retire and actually pursue your real interests!

This instructable is entered in the "Wireless" contest. Please vote for me, Thank you

When I moved to a rural property in Australia I was faced with the fact my water supply was at the mercy of the Gods; rain from the sky to fill the tanks.

I had a capacity of around 30,000 litres across 2 concrete tanks and checking the levels meant climbing up a ladder, lifting a very heavy concrete cover and peering down into the damp darkness to estimate the levels.

Not much fun, inaccurate and time consuming, there must be an easier way.

Using Blynk and my WLAN was the answer, I could see at a glance the levels on my phone.

Check out Blynk here

Please note:
The DC-DC converter proved problematic. I now power this with a USB charger plugged into the USB port of the ESP8266 board. 5V for the sensor is taken from the "USB out" pin on the ESP8266 board. The signal of the sensor is connected to the Arduino via a Level Shifter board. HERE

Step 1: The Hardware

The standard HC-SR04 ultrasonic sensors are not waterproof, waterproof ultrasonic transmitter/receiver sensors to the rescue. These are the same units used on motor vehicles for reversing and hazard detection. These coupled to an ESP8266 NodeMCU WiFi board plus a small power regulator board make up the hardware.

These parts can be bought from AliExpress very cheaply (links below) or the supplier of your choice.

ESP8266 NodeMcu-V3-Lua-WIFI

Waterproof Ultrasonic Sensor

DC-DC 3.3v supply

Plus a waterproof box big enough to fit all the boards in.

Breadboard for testing

Link wires

LED color of your choice

Plug pack, 9 - 12VDC with Arduino UNO compatible type connector

Please note:

The DC-DC converter proved problematic.

I now power this with a USB charger plugged into the USB port of the ESP8266 board.

5V for the sensor is taken from the "USB out" pin on the ESP8266 board.

The signal of the sensor is connected to the Arduino via a Level Shifter board. HERE

Step 2: Wiring It Together on the Bench for Initial Testing

I used a breadboard for initial setup and testing.

For testing purposes this can run off the USB supply from your PC but in the field I used a small 3v3 regulated DC-DC converter supplied by a 9v plug pack. A 12v supply could be used with these converters. Use what you have laying around.

Plug the 2 ultrasound sensor boards directly into the breadboard and run 2 wires for each to the Arduino as below. Be aware these ESP12E boards run on 3.3 volts. They have a 5v input supply pin (VIN) and also run on the USB supply when connected to your PC. Do not supply more than 5 volts to the VIN pin if you use that.

Wire using male to female link wires:

Sensor1 ping to Arduino GPIO5 (D1)

Sensor1 echo to Arduino GPIO4 (D2)

Sensor2 ping to Arduino GPIO14 (D5)

Sensor2 echo to Arduino GPIO12 (D6)

These sensors work ok at 3.3volts. This is good as level converters are not needed.

It's probably a good idea to take the supply and ground for the sensor boards from the DC-DC converter output pins when doing the final wiring in the box but for testing use the Arduino 3v3 and GND pins.

Wire both sensors VCC to Arduino 3v3

Wire both sensors GND to Arduino GND

The LED is only on for 50mS every 2 seconds so I didn't bother with a current limiting resistor but a 1/4W 470R resistor can be added if you wish.

LED Anode (long leg) to Arduino GPIO13 (D7) Through a resistor if desired

LED Cathode to Arduino GND

Now plug the Sensors into the back of the sensor boards, they have 2 mtr long co-axial leads.

I needed to extend these, my tanks are 6 mtrs apart. I used some old co-axial cable I had laying around.

If you do this, be sure to cover all soldered joints with heatshrink.

That's all the wiring, next is the software.

Step 3: Collecting and Installing the Software

This water level monitor uses Blynk to send info from the ESP8266 board to your phone via their servers.

The Blynk server in the cloud serves up your app with the information in the widgets on the phone. When signing up with Blynk you are given 2000 energy points. These points are used to 'buy' widgets for your program.

2000 points is enough to build this water monitor app.

I actually have a 'local server' running on a Raspberry Pi, this allows unlimited points and better security. It does not use the Blynk server at all, completely independent.

Installation and setup of a local server is beyond the scope of this instructable. There are many instructions and tutorials on the net for doing this starting with the Blynk website.

The final version I coded for OTA (over the Air) updating as it is remote and I didn't want to pull it all apart just to update the software. I'll discuss the OTA software changes and methods later.

While on the bench we have the USB serial to upload code.

First thing you will need is the Arduino IDE if you don't already have it.

Get the Arduino IDE here Arduino IDE. Follow the getting started link on how to install this software, it is not part of this instructable.

Download the Blynk library here Blynk library, download link is at the bottom of the page.

Follow the instructions on that page to install the library.

Get the phone app here Blynk App.

An account can be created now for Blynk if you wish using the app. Remember the login email address you use, you'll need it later. Probably best to use your every day email account.

You will also need this library:

NewPing This is an excellent library for using ultrasound devices that does all the timing for you. No need to mess around with milliseconds etc.

These instructions below need to be done to install all the ESP8266 software.

Starting with 1.6.4, Arduino allows installation of third-party platform packages using Boards Manager. We have packages available for Windows, Mac OS, and Linux (32 and 64 bit).

Start Arduino and open File > Preferences window.

Enter ( copy and paste - without the quote marks) ```http://arduino.esp8266.com/stable/package_esp8266com_index.json``` into *Additional Board Manager URLs* field. You can add multiple URLs, separating them with commas.

Open Boards Manager from Tools > Board menu and install *esp8266* platform (and don't forget to select your 'NodeMCU 1.0 (ESP-12E Module)' board from Tools > Board menu after installation).

From the menu select Sketch > Include Library > Manage Libraries. Allow it to finish downloading. You should see the Blynk libraries installed.

For your PC to communicate with the Arduino boards the USB to Serial software (We ESP12 USB-UART CH341SER_win driver) needs to be installed. This is needed for all Arduino comms over USB. Get it here

That's all the software set up hopefully.

Step 4: Test Code for the ESP8266 Board

When I write software I like to build it up from small beginnings and continue testing as I go.Writing a long program and finding it doesn't work is difficult to debug.

So we'll start with two sensors reporting back the information to the serial monitor built into the Arduino IDE.

No reporting to the Blynk server, OTA or WiFi yet.

Double click the 'water_code_1.ino' file below, after Arduino IDE starts go to File > 'save as' and save to your sketch folder.

A folder will be created with the ino file inside.

Confirm you have the correct board selected, click the 'verify' button (very left button on the IDE). It should compile without error.

Connect your board to the USB cable, select from the IDE menu Tools > Port > COM n.

The correct com port can be found by simply unplugging the board and see which port disappears.

Click the 'Upload' button in the Arduino IDE and allow it to finish compiling and uploading.

In the IDE select Tools . Serial Monitor.

The LED should flash every 2 seconds and the monitor should be reporting distance, depth and liters for each tank every 2 seconds similar to the picture shown.

These sensors have a range of about 3 mtrs They are set at 3 mtrs in software anyway.

Test each sensor by moving it in and out from a solid object like the wall, you should see the figures change in the monitor window. As the distance increases this is simulating a lower water level so less liters will be reported and vise-versa.

If all works as expected go to the next step.

Step 5: Code With WiFi and Blynk

Now lets get connected to the Blynk server.

download and open the water_code_2.ino

In the Arduino IDE select File > 'save as' to your sketch folder.

Open the Blynk app, sign in. Create a new project, chose device = ESP8266, connection type = WiFi, set the theme you prefer. press the Create Button.

An authority token will be sent to your nominated email account. press OK. Further instructions on the app program in the next step.

go to your email and copy the authority token, paste it into your arduino program where it says 'char auth[] = "YourAuthToken"

Also enter your SSID and your password.

Now upload it to your ESP board.The serial monitor should display connection status before it displays the water levels.

In the next step we will finish the Blynk project in the app.

Step 6: Setting Up the Blynk App Program

Continuation of new project in the Blynk app....

Press the + at the top of the screen in the app, scroll down and press Value Display. Do this 4 times

Press the + at the top of the screen in the app, scroll down and press LevelV. Do this twice

Press the + at the top of the screen in the app, scroll down and press SuperChart.

Lay out the widgets like the picture. A long press on the widget gives you handles to resize them.

Color them as you see fit.

Press the first Value Display (top left), name it Depth 1, select V1, 0 to 300 and PUSH

Press the second Value Display (top right), name Depth 2, select V4, 0 to 300 and PUSH

Press the third Value Display (2 down left), name Liters 1, select V2, 0 to 9999 and PUSH

Press the forth Value Display (second down right), name Liters 2, select V5, 0 to 9999 and PUSH

Press the left Vertical Level, name it Level 1, select V3, 0 to 1600, OFF and PUSH

Press the right Vertical Level, name it Level 2, select V6, 0 to 1600, OFF and PUSH

Press the SuperChart, names Liters 1 and Liters 2.

Press the icon (data stream) next to Name, PIN = V3, slide switch = VALUES, minn = 0, max = 1600

Press the icon (data stream) next to the second name, PIN = V6, slide switch = VALUES, min = 0, max = 1600

You can play around with the other settings to suit your preferences.

To delete a widget drag it to the top right of the screen.

If everything looks ok, press the play button top right of the screen. If your Arduino is running you should see the same numbers (except distance) come up as in the serial monitor.

Step 7: Setting Up OTA Updating

OTA or 'Over The Air' uploading of code is a really a useful feature, particularly in this case where the ESP board is in a box and outside.

This is a fairly simple process:

1. a OTA bootloader is first uploaded to the board.

2. The board is reset by pressing the reset button on the board.

3. your new code for the water tank project containing the OTA additions is uploaded to your board by USB.

Future uploads are achieved by selecting the WiFi port in Tools > Port.

Go to File > Examples > ArduinoOTA > BasicOTA

The program will load up, enter your Network Name and Password in the code near the top f the program.

Upload this to your board.

Now press the reset button on the board.

Go back to your water tank program and un-comment the 3 places shown in the pictures, these are required now for OTA uploading.

Upload this to your board, use serial USB.

If you look under Tools > Port in the Arduino IDE you will notice a new port. It will have 'esp8266', the board ID and the board IP address.

For future upload use this port, no need for a USB serial connection.

The board can now be powered by some other means but OTA will still work using power from the USB cable.

Step 8: Mount the Boards Into the Box

I mounted the ESP8266, both the Ultrasonic boards and the DC-DC converter in a IP66 rated box as it would be outside and exposed to the elements. I did however put the box inside a UV safe plastic bag just to be sure. I felt the connectors could leak water into the box.

I wont go into detail about mounting the boards; your box may be different to the one I used.

I didn't have any female connectors for the Sensor boards so I soldered the wires and covered with heatshrink.

If you have female-female wire links, all the better.

Mount the DC-DC converter to a position where the power connector can be plugged in from outside.

Take all the power and ground connections to this board so we avoid ground loops. Use 3.3 volts for everything.

Drill a hole for the LED, try to make it a tight fit so no adhesive is necessary.

Check everything, especially the power wiring.

Plug in the power pack and connect to the box, plug in the sensors and switch on.

You will not see anything on the serial monitor of course as we are not using the USB serial connection, but check your phone app.

Move the sensors around, the figures should change in the app.Bear in mind a ping and info transmission is only done every 2 seconds.

Step 9: Mount the Sensors in the Tanks

Again I cant go into detail about mounting the sensors in the water tanks, your tanks are most likely different to mine.

It does however have to be within your homes WLAN WiFi envelope. If your tanks are at a greater distance, WiFi extender could be used.

However, fix the sensors pointing directly vertically downwards toward the water at the height you measured before, see the picture, should be at 'Depth1 and Depth2. It is assumed the water can never reach this depth before overflowing. You don't want the sensors drowning.

I should also point out these sensors have a minimum range distance of 20 cm, this is because the transmitter and the receiver share the same ultrasonic speaker and has speed/timing problems under that distance.

Connect everything up and ensure everything is weather proof.

Apply power, it takes a few seconds to boot, you should see the water levels on your phones Blynk app.

Any questions I will try to answer as best I can. Good luck with this useful project.

Don't forget, if you like this instructable, please vote for me in the wireless Contest. Thanks

Wireless Contest

Runner Up in the
Wireless Contest

3 People Made This Project!


  • Home and Garden Contest

    Home and Garden Contest
  • Origami Speed Challenge

    Origami Speed Challenge
  • Woodworking Contest

    Woodworking Contest



1 year ago

Hi All
I am at the first stage of the project and uploaded the first code to my NodeMCU-32S board and get this. I changed the Blynk library to this
#include <BlynkSimpleEsp32.h>
and changed pins but that's the only thing I changed
The readings are fine and accurate and I'm only using 1 sensor.
How do I get rid of this.

The assertion "Invalid mbox" failed: file "/home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/lwip/lwip/src/api/tcpip.c", line 374, function: tcpip_send_msg_wait_sem
abort() was called at PC 0x400d7b47 on core 1

ELF file SHA256: 0000000000000000

Backtrace: 0x400850b8:0x3ffb1db0 0x40085335:0x3ffb1dd0 0x400d7b47:0x3ffb1df0 0x400e78d3:0x3ffb1e20 0x400e736d:0x3ffb1e50 0x400e7520:0x3ffb1e70 0x400eaa74:0x3ffb1eb0 0x400d2d86:0x3ffb1ed0 0x400d2786:0x3ffb1f20 0x400d224a:0x3ffb1f50 0x400d22bd:0x3ffb1f90 0x400d3c05:0x3ffb1fb0 0x40086336:0x3ffb1fd0

ets Jun 8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
mode:DIO, clock div:1
entry 0x400806a8


Reply 6 months ago

I'm using the same board and having exactly the same problem. Tried lots of things, but nothing cured it. The board seems to work fine with other sketches, so it's something with this sketch. My guess is the incompatibility is in the newping library. Did you ever solve the problem?


8 months ago

I have a problem with the tank level always reading 0. I am using the FULQ9X1JA36MS3S sketch with a JSN-SR04T-2.0 transducer.
The sketch compiles correctly but I do not get any reading. I have tested the transducer with the following sketch and it works fine.
The issue appears to be with the NEWPING library. I have tried various sketches using this library and none of them work. Reading other posts it appears there is a difference between the original JSN-SR04T and the V2.0 causing the problem.
I am wondering if you have tried this with the V2.0 transducer and if there is a solution to the issue.
Any help would be appreciated.

Working code:
// Define Trig and Echo pin:
#define trigPin 5
#define echoPin 4
// Define variables:
long duration;
int distance;
void setup() {
// Define inputs and outputs
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT_PULLUP);
// Begin Serial communication at a baudrate of 9600:
void loop() {
// Clear the trigPin by setting it LOW:
digitalWrite(trigPin, LOW);
// Trigger the sensor by setting the trigPin high for 10 microseconds:
digitalWrite(trigPin, HIGH);
digitalWrite(trigPin, LOW);
// Read the echoPin. pulseIn() returns the duration (length of the pulse) in microseconds:
duration = pulseIn(echoPin, HIGH);
// Calculate the distance:
distance = duration*0.034/2;
// Print the distance on the Serial Monitor (Ctrl+Shift+M):
Serial.print("Distance = ");
Serial.println(" cm");

working code.jpg

Tip 3 years ago

Hi, thanks for a great project. In my case the deposit was more then 20 meters away from the nearest Wifi point and the coax signal did not survive this distance. So I chose to put the little sensor circuit board close to the sensor (in a closed casing) and used a 4 wire shielded cable to connect it to my Wemos. No problem with 25m distance at all.
By the way, my deposit is cylindrical horizontal so to get the right readings I incorporated another formula (using arccos function) I am happy to share if someone needs it.
Blynk also was very easy to install and adapt to my needs.


Reply 1 year ago

Hi, thanks for the offer to share the code for the horizontal cylinder. I would be very grateful if you could share with me.


Reply 1 year ago

Sure, I hope this works out for you. If not please contact me again.
Gr. Guus

#include <math.h> /* sqrt */
#include <math.h> /* acos */
#include <math.h> /*round */
#define PI 3.1415926535897932384626433832795

My tank dimensions:
const int Dia = 240; //internal diameter of tank cm
const int L = 221; //total length of tank cm
const int Vt = 10000; //total volume of tank in L

//***********Readings Tank 1
h = sonar[0].ping_cm(); //get distance to the top of the water tank 1
h=h/10; // convert to dm
r=Dia/20; // convert to radius in dm
Vu = L/10*(r*r*acos((r-h)/r)-(r-h)*sqrt(r*r-(r-h)*(r-h))); // calculate used up volume
Vl=Vt-Vu; //calculate left volume

//***********SEND INFO TO BLYNK
Blynk.virtualWrite(V1, round (Dia-h*10)); //send depth to Blynk server
Blynk.virtualWrite(V2, round (Vl)); //send litres to Blynk server


Reply 1 year ago

Thank you Gus. I will give it a try. Regards


Reply 1 year ago

Did you build this project with a wemos d1 mini?


Reply 1 year ago

Yes I have used the Wemos D1 mini


1 year ago

Hello again. can this run on wemos di mini ?


Reply 1 year ago

It does (d1 mini pro); It was my first project and I changed some things (different pin-settings, couldn't get readings with the NewPingESP8266 library so did the math within the sketch) but all seems to work fine now


Question 1 year ago

Fantastic project. Just built and tested.
Could anyone point me in the right direction for a notification email/pushover if tank has high/low level?


Question 1 year ago on Step 9

i want to make similar project but have a different sensor. its a non-contact water level sensor also from aliexpress, hoping someone knows how to do this using a different sensor, its similar in that it senses fluid on other side of tank wall (it adheres to the outside of the tank)


Question 2 years ago on Introduction

Hi Graham
Further to my last, I uninstalled and reinstalled IDE and have found that I can compile the code, however I still think that Im either using the wrong version of the NEWPING library as I get these errors when compiling code: The URL in your PDF goes to a non-existent page on Github so am unsure as to what version of the Library I should be targetting. Ive attached a pic of my board for info.

WARNING: library NewPing claims to run on avr, arm architecture(s) and may be incompatible with your current board which runs on esp8266 architecture(s).
Executable segment sizes:
IROM : 247984 - code in flash (default or ICACHE_FLASH_ATTR)
IRAM : 27964 / 32768 - code in IRAM (ICACHE_RAM_ATTR, ISRs...)
DATA : 1324 ) - initialized variables (global, static) in RAM/HEAP
RODATA : 2028 ) / 81920 - constants (global, static) in RAM/HEAP
BSS : 26176 ) - zeroed variables (global, static) in RAM/HEAP
Sketch uses 279300 bytes (26%) of program storage space. Maximum is 1044464 bytes.
Global variables use 29528 bytes (36%) of dynamic memory, leaving 52392 bytes for local variables. Maximum is 81920 bytes.




Answer 1 year ago

What sort of sensor are you using also, I’ve read that beeping library only works with the JSN branded sensors. Not the cheaper clones that you get of banggood and AliExpress


Answer 1 year ago

Hello! I have the same problem here. Hope someone can help us.


1 year ago

Hey mate, great instructables; I’m building something similar and trying to come up with mounting solutions and alternative measurements (pressure sensors). Seems to have been a year or two since you posted and wondering if your set up is still operational, or have you made any changes/improvements?


1 year ago

Hi ItsGraGra - Thanks for putting this up! I thought I would have to design the whole setup from scratch, this is definitely food for thought. Much like you, I am in South East QLD, and have a pair of switchable concrete 22,500ltr tanks servicing the house. I also have another tank further away, and was wanting to set all three up with wifi/solar powered senders, and allow for future expansion. So thanks for the info, your approach looks excellent, and the instructions look detailed.


3 years ago

Hello again. I am currently building this project and I got some questions.
1)What happens if the minimum range distance is less than 20cm
2)I have a square 1tone tank. So in const int Area1 I have to put 1.000.000 ?
3) Program compiles and uploads succeful but I have no measuring from the minitor