Ultrasonic watertank Level meter

I am using an Arduino board with in-built ESP8266 for my wifi connected EmonTx shield

Once I get that project operating, I would like to automate my water tank level reading (We live on rural acreage, relying on rain water). The idea is to feed the data to EmonCMS (private server), then use that data, as well as solar data to control pumps to move water. I want to have all connected by wifi for ease of use.

There are heaps of designs on the web for Arduino shields using ultrasonic transducers to measure water level (so no need to re-invent the wheel!), but there will be work required for the ESP8266 communication. This project will be powered by a small solar panel & Lithium Ion battery (because you do not want to climb a 7.5M water tank tower very often!). The best Ultrasonic sensor to use is the waterproof one available from AliExpress (& others) for a few $. (These are used on cars for parking sensors as an example)

A suggestion to the developers of the ESP8266 code is to allow bi-directional communication. I would also like to use the ESP8266 as a load controller (using a Solid State Relay) to switch on pumps for this project.

Eventually, I would like a fail-safe control system (possibly running on the EmonBase) to check levels while transfer pumping to ensure everything is OK. Living on Rainwater you cannot afford to lose water!

If anyone wants to start this project please keep me informed. I think it is applicable to the Emon project because water is another sustainability issue. Also this project could monitor other data, such as a hopper for an auto-feed boiler (using woodchip for instance).

To be clear… are you wanting someone to design the system & write the code for you?

No, not someone to write the code. I am not a programmer, but I should be able to adapt other code to perform the task. However, I will need to use some modules from Emon project such as the ESP8266 code. As I said, I am not sure if this is bi-directional atm. It would need to be for this project (& possibly others).
Once the system software goes modular, it should be relatively easy to write & add a program to monitor the tank levels.

Judging by the number of projects reading tank levels (on the web), I think I will get some positive responses. Having the data web-accessible will, I think, tick some boxes. (Nothing worse than being away & having someone ring you to tell you the header tank has run out of water!)
regards, Doug

Just use a Sonoff device. Now has a weatherproof case available.

Thanks, but I prefer Wifi devices.

regards, Doug

Hello Doug, the Sonoff devices have an ESP8266 WIFI module inside that you can program with your own firmware and are great pieces of kit.

Here’s an example using the Sonoff S20 smartplug:

There’s also a small inline modules e.g:

It is a WiFi device (as Trystan said). If you want more control over the data, you can flash the device with Tasmota.

If you can wait, order them direct from Itead in China and get the latest revision.

instead of using the wemos R3 you should simplify it and just use the wemos D1 R2 ( no ardiuno)… not sure how long your range finder going to survive in a hot moist environment- you be better off using an analog 16 channel multiplerer and place 16 pad spaced evenly apart in your tank and use a basic moisture sensor code to figure out the water level… or use a water pressure sensor - and say mount it on your drain bunk - fill your tank take a reading drain it to point the sensor does not read any more or your tank is empty - and then do the math to calculate your volume . though not sure if this sensor is accurate enough for you . as ~8 meter of water is ~ 0.08 mpa ( 11 psi)-- and this sensor is 0-1.6 mpa so it give only ~50 steps out of 1024 on a 8bit analog . but look around you might find a a more accurate water pressure sensor then this one – or possibly install 10 bit analog to get a few more steps

Thanks for the feedback. The ultrasonic sensors are the sam as is used on auto bumper bars, so should handle the environment. They have a section of lead (1M?) so the box can be a bit isolated.

I have also considered using the stainless float switches. These use a stainless tube, with a stainless float that has a magnet in it. The float can be reversed to be either nc or no. They also have 2 sensors on one stem (about 450mm long). I was thinking of mounting them on a plastic tube, so I have top, bottom, & a few steps in the middle.

One problem with roof water is sometimes it is pure enough to be non-conductive.

I think I will go with the Ultrasonic method, because the code is written already.

regards, Doug

8 bit analog would be a maximum of 256 steps.

10 bits represent 1024 steps.

When I was on tank water, having even 128 (half of 256) steps of “tank level” would have been fantastic :slight_smile:

oops my mistake on bits- but so make that 10bit (normal arduino/esp- analog is 1024) and 12 bit 4096 ( 200 steps as opposed to 50 earlier )

code would be simple for the pressure sensor if you are worried about that you just use the basic analog sensor read and expand it here a quick example based on that water pressure sensor mentioned :

//0.009807 mpa per meter

float top = 7.5; //distance  in meters to top of  tank or water from where sensor is located 
float bottom= 3; //bottom of tank distance from sensor 
float step = 1024; //analog read step
float sensorrange = 1.6; //ie 0 - 1.6 mpa
float indivstep ; //indvidual step
int  maxstep; //max step
int  minstep; //min step
int  valve; 

void setup() {
// calculates the range of your tank based on your variables
invidstep =  (sensorrange/step); //calculates the value of the individual step
maxstep = ((top*0.009807)/indivstep);  //calculates where the  maximum location 
minstep = ((bottom*0.009807)/indivstep); // calculates the minimum steps location

  // initialize serial communication at 9600 bits per second:


// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin 0:
  int sensorValue = analogRead(A0);
  // print out the value you read:
//figures out what percentage your tank is at 
if (sensorValue <=maxstep && >= minstep){
value = SensorValue - minstep; // brings the  min value down  to zero
int divisor;
divisor = (maxstep-minstep); //  calculates the divisor 
int percentage;
percentage= ((value/divisor)*100); //   and rounds down the value 
Serial.print( "your tank is  ");
Serial.println (" %  full");
  delay(1000);        // delay for one second in between reads 

is you want it to shut off your water by controlling an SSR just add in to void setup

pinMode(7, OUTPUT);

and to the bottom of void loop above the the last }

if( percentage <5){  // 5 is your defined minimum water level
digitalWrite(7, HIGH); // turns off SSR ie no power to your pump
digitalWrite(7, LOW); // turns on SSR

oh well just an added option for you if you like it untested but should work unless i have typo somewhere - best thing about it you install every thing at ground level no need to climb and if you have issue every thing right there for you easily reachable

Thanks (& Merry Christmas all so inclined!)

I am currently waiting on the boards & parts to get my Emon running.

I have found 2 of 9vAC plugpacks for the AC monitoring (Australian: Old Netcomm transformer plugpacks: just hit with a calibrated hammer to open case, then remove rectifier, etc. Luckily had 2 so both will be the same for 2 phase)

The Tank level is for later, but I always debug on the ground before going 7.5M up the stand!.

regards, Doug

I’ve tried the ultrasonic sensor with no sucess, I used two of them

The one that has two metallic “speakers” (hc-sr04):
Guess what happened? of course, it got rusty.

The one wheather proof (jsn sr04t):
I’ve tried a couple of them but none give good accuracy, them give some erratic measurements randomly.

I used a sensor laser, is more expensive but pretty accurate (and has a huge range, from about 3cm to 50m or 1 inch to 160 ft), with a floater that reflects the laser, and a nylon across the center, from te sensor to tank bottom, to guide it at the same position.

I’m curious, why use an arduino and a ESP8266? I did this with a NodeMCU, but I don’t used openenergymonitor server, I’m working with another cloud, I doubt that’s a limitation.

Thanks Edgar.
good information. I have some stainless float switches I will probably use. These work with a collar/float magnet & a reed switch. I think if I use one near the bottom, 2 intermediate & 2 at the top, with the uppermost switch being the ´overfull safety switch´. The switches will short out sections of the resistor string, which can be measured by an a:d measurement.
The reason for wanting to use OpenEnergy is I am hoping in the future it may move towards a virtual power plant (by being able to set the battery system to export to the grid with an external command). I feel there is a need for this capability. Therefore, the more energy projects we can incorporate into OE, the closer we come to an overall energy management system.
The Uno+ESP8266 suits my project where I want to monitor my 2 phase system, but need external antennae due to the solar setup being in a metal shed. I will probably use an ESP8266 for the tank monitor. (its a a future project, delayed by my issues getting my energy monitor working.)

regards, Doug