Before delving into the code, it can be helpful for me to start with the physical design.
Imagine a 100m tall tank with sensors placed at 25m, 50m, and 75m (let’s call the lowest sensor #1, and the highest #3).
The knowledge you have about the level of fluid in the tank based on the sensor readings is:
All sensors dry: less than 25m
Sensor 1 wet, others dry: above 25m, below 50m
Sensors 1 & 2 wet, sensor 3 dry: above 50m, below 75m
All sensors wet: above 75m
Depending on what you will do with this information will dictate your algorithm. For instance if you just want a description of the tank level, you could translate “all sensors dry” into “less than 25m” or “less than 25%”.
If you need to know when the tank is truly full and fully empty, you would need to add a sensor at the bottom and another at the top.
tks for your reply… the goal is to know the level of water in the motorhome…This information will help me to plan the next refilled .Having a % is good.
It all depends on how accurately you need the level percentage and how much you are willing to spend to achieve this result.
I have a gray water tank in the basement with a sump pump in it. I never cared about the level, until the pump stopped working.
I put a ToF sensor in there, because it is cool, but I guess I didn’t look at it enough (and didn’t get an alert set up). I finally replaced the float switch and things are much better. I also put a level sensor about where the float turns on and below where the tank overflows that turns on a buzzer. That works well for me.
I had a similar challenge with a cistern. I had two sensors which were “empty” and “full” I finally bit the bullet and bought a water level sensor (get 0-190Ω). If your tank is 325mm it cost USD$16.38. ESP8266, power for it, and a 480Ω resistor. Select one that is the right depth for your tank and you’ll have 1024 levels (not really, as the ADC is a little noisy, and the resistor has tolerance, so 200 levels? )