Ultrasonic Sensor - HC-SR04

Hi Everyone
I am planning to measure water tank level percentage using home assistant and Ultrasonic Sensor HC-SR04 with nodemcu (mqtt connection).
Is someone working on similar project ? or someone has better idea to measure water level?
Thanks

1 Like

How precise do you need the measurements to be?
How do you plan to power the nodemcu?

I am planning something similar, but in my case it’s not water, but liquid chlorine in a small barrel that feeds into a pool chlorinator.
I looked at various different options (this article describes basically all imaginable options) - and I ended up with ultrasonic because it’s reasonably cheap, and can be implemented without changing too much in the whole setup. I decided to go with a waterproof version because the barrel is outside, and chlorine is highly corrosive. I guess the HC-SR04 version would not survive for long in my setup.
The disadvantage of the waterproof sensor though is the minimum distance of ~30cm. In my particular case with a ~60cm high barrel I will only be able to measure the level between 0-50%. I am primarily interested to better predict when I am going to run low on liquid chorine, so that I can refill in time.
I just received a NodeMCU board to play around with. The plan is to put this into a waterproof case with a battery and a little solar panel, and also add a water temperature sensor to the whole setup.

Easiest solution:
https://www.letscontrolit.com/wiki/index.php/DistanceSensor and use an MQTT sersor.
BUT: I ordered 5 of them from china and all have an electrical defect where they freeze after a certain amount of dime / detections. Maybe you should order a better one.

Thanks all for your suggestions. I have decided to go with waterproof ultrasonic sensor.
I am able to get the level of water on home assistant screen and automate waterpump to turn on and off depending on water level.

solved by myslef. please ignore the post below
But since my water pump is starter controlled with relay ( with on and off push buttons). I want to trigger relay for 3 seconds to latch the main relay. The config. is below, if i dont use

  for:
     seconds: 3

automation works fine. I think i am not using for: statement properly.

automation 1:
 alias: turn on pump if water is less than 100L.
 trigger:
  platform: numeric_state
  entity_id: sensor.distance
  below: 100
  for:
     seconds: 3
 action:
  service: switch.turn_on
  entity_id: switch.water
  
  
automation 2:
 alias: turn off pump if water is above 980L.
 trigger:
  platform: numeric_state
  entity_id: sensor.distance
  above: 980
 action:
  service: switch.turn_off
  entity_id: switch.water

solved by myslef. please ignore this post

https://circuits.io/circuits/2490973-esp-12e-water-level-meter-with-lcd#pcb

I have made this project previously here.

Enjoy

Hi can you share how you build it? Have you got a write up?
Thank you

In case someone is still looking for a solution this works and it’s much easier:
https://hackaday.io/project/25090/instructions

Can’t download the file anymore?can you share it?

Sure, this is the ino file. I relabelled as .yaml so I could upload it.

Thanks will try it…

I am trying to have a crack at this as well. Complete newbie but have managed to cobble together the feather huzzah to speak with hassio mqtt.
Given my real ignorance with coding (learning, learning) I can find an example that tries to talk with adafruitIO. I want to use my own mqtt but when I start trying to interchange code it all goes pear shaped.
Does anyone have coding for using the feather huzzah an hc sro4 and pointing to their own ip mqtt server that I can adapt?
thanks

Update - issue solved. Running espeasy mega and the correct syntax in mqtt and all is good

Hi, how do you reduced the scan time for sr04? Because home assistant scan every 5 minutes and I don’t know how to reduce this time. Also scan_interval doesn’t work. Thank you

Hi if you look at my github I have done this exact project with that sensor just used a pycom instead.

It’s using mqtt sensor

1 Like

how display distance water level in percent in home assistant?
Min value : 25cm
Max value : 85cm
x value: the value measure
%(percent) = x/(85-25)
Please help

Hi Juan,
Thanks for pointing me to the right direction. I got it working but I would like to reverse the value in lovelace that if the value (distance) from the sensor is higher, meaning the water level is low, I would like the guage to read low too, not high. Any idea?

Michael, I would suggest using a template sensor to adjust to your liking.
For sample jinja templatting search in the forum for examples

Hello,

I use this formula for the rest in my oil tank.I have a espeasy.
size of the tank in centimeters = 125 CM
size of the tank in liter = 3000 L

(125-%value%)*3000/125

Hi,
I am doing something similar. Can you share your esphome yaml code/automation code?
I am planning to turn on/off a tasmotized sonoff based on the water level.
Thanks. Any help is greatly appreciated.

did you use ESPHome? i am using a waterproof sonic sensor too but my sensor is stuck at .23meters.