ESPHome water level sensor

Assuming sensor is powered with 24V and max current flow is 20mA it gives 0,48W of energy. This with 5V is 96mA. Taking some margins and assuming 90% efficiency of step-up module we get something around 140-150mA from 5V source (0,75W).
ESP8266 takes (from my measurement) 700-900mA, so together I would need 1,1 - 1,2 A to be safe.
I would go this was as I have several ESP8266 in my environment and I want all of them to be powered by cable from one central source which is also backed up with UPS.
Now, it happens that my entry gate is powered by 24V and is close to my tank to I decided to use those 24V for powering sensor and my standard 5V to power ESP8266.

1 Like

What kind of sensor are you using ?

FYI hereā€™s a video about the built in ADCā€™s in the ESP8266 and ESP32.

Conclusion: ESP8266ā€™s ADC inaccuracy can be fixed with some coding. ESP32ā€™s ADC is garbage. This cheap dedicated ADC is excellent and does not need any fixing.

Did your current to voltage converter arrive? Did you get it to work?

Most of the things I need have arrived and I decided to do some testing.
First thing was to put 24V on the pressure sensor and measure the amperage with a multimeter.
In this drawing you can see how I took a USB powered ESP8266, converted the 5V from there to 24V and connected this 24V to the pressure sensor (with a multimeter in between). It shows 4mA when not submerged and Ā±6mA when I put it in a bucket of water. So far so good!

However the current to voltage converter doesnā€™t work for me. I put this converter where the multimeter used to be on my previous drawing, and give the converter itself 24V of power:


Result: the thing starts smoking and a burning smell appears. The Vout doesnā€™t give a voltage.
If I just power on the converter with 24V but donā€™t put anything on I+ and I-, the thing first makes a lot of noise and the indicator light blinks a lot. After a while the noise stops and the light goes solid. However if I put a lower voltage (itā€™s supposed to work on 7-36V) the light wonā€™t stay on. The component which Iā€™ve indicated with a green arrow gets Ā±130Ā°c warm!!!

Am I doing something wrong?
image

I think Iā€™ll be buying this one from DFRobot instead.

Unfortunately my order from Aliexpress got stucked somewhere (was send 38 days and is still not in my country :frowning: ), so I need to contact seller and investigate status.

For your connections all seems correct. At the same time if the module gets hot this is not good.
Do you have only 1 ordered (there is a small chance that it was brokenā€¦) or more to test other ?
What if you power module from one source (12V lets say) and sensor from another source (in a way in your case you are connecting VCC with + input for current sensor and I do not know if the sensing part is somehow isolated/resistant to this ?).
And IMO with no sensor connected at all module should start working, no part should get hot (not more then 40-50C) and you should get close to zero voltage on Vout which can be regulated with ā€œTurn zeroā€ potentiometer.
Also did you play with jumpers (maybe there is some bad connection) just to see if this changes anything (with no sensor connected).
The element which gets hot is names U2 and looks like transistor or similar active component. Also double check + and - of connection (I know it is obvious but happen something ā€¦ :frowning:
Last I would maybe try to connect sensor between Vout of setp-up module and + input of the sensor.
And last think which comes to my mind is the fact that setup module does produce some noice, which current to voltage converter does not like ? And maybe putting capacitor at the output may help ? This actually woudl be eliminated if you power the module from batteryā€¦
I keep fingers crossed for your testing ā€¦ !

2 Likes

Surprisingly today I have got my modules.
So afternoon started to test them knowing @quizzical issues. Andā€¦ unfortunately there is something wrong with them :frowning:

  1. They seem to be OK with Vcc between 5 and 12V. Over 12V power-LED goes off and increacing Vcc get the led to flicker and module to give strange noice. The part indicated by @quizzical is getting hot (power consumption by module goes to above 150mA). BTW I can that this part is linear voltage regulator LM317LZ
  2. I was trying to simulate current load to input and it does not seem to work. I have stable Vout voltage regardless of current I regulate. I was however able to make 0V with ā€œzeroā€ regulator.
  3. On my board/module there is a symbol HW-685 - I can see this site with information about this module, where it says that Vcc is between 5 and 12V !

It seems that my both modules behave the same.
Is it possible that information on the Aliexpress seller page is so wrong ? (Vcc up to 37V)
And that reviews of this product are so good ?

Not happy :frowning: :frowning: :frowning:

EDITED 18.3.2021
Based on the link above I have made another test powering module with Vcc=5V (red power LED is going on but not as strong as with 12V). It seems that with such power hte module is working correctly. I was able to adjust zero and max 3V when current was 20mA. Regulating current between 4 and 20 mA Vout was changing from 0 to 3 V.
So this is positive. Next step will be to connect to my system/sensor and see the live results.
(Still shocked with the many available information that module power is from 7 to 34 V !)

1 Like

Thanks for your insights. Based on your feedback I tried powering the current to voltage with 5V and sure enough the light was steady and nothing was extreely hot. So far so good.
But then I connected my pressure sensor which has 24V on it. As soon as I put power on the system there was a component which immediately caught fire. On my previous post itā€™s the device called the ā€˜current signal sampling resistorā€™.
Perhaps because of the abuse it has allready had before when I used 24V instead of 5V? In any case it looks like this is not for meā€¦ Iā€™m patiently waiting for the DFRobot one to arrive.

Looking forward for your test of DFRobot.
The one possible explanation for your ā€œfireā€ on the board could be connection 24V just to the board (or some shortcut on the sensor cables) in which case you are creating 240mA current (I have measured the resistance of this ā€œpreciseā€ resistor and is equal 100 Ohm). Important in connecting is to make sure that GND of 24V is connected to ā€œ-ā€ of the current sensor connector (as this is connected with GND of power supply). So I think, safe connection would be +24V to + of the sensor, - of the sensor to + of current sensor connector, - of current sensor connector to GND of 24V. Especially if you are using setp-up module (in which GND of input is connected with GND of output).

I am also thinking of another test to just connect high precision resistor (lets say 0,05%) with value selected to my measures and needs. ESP8266 NodeMCU (which I am using) can measure on A0 voltage from 0 to 3,3V. My tank can only be filled up to 1,4m level which corresponds to appr. 8,5mA of sensor current. So I need to use resistor which with lets say 9mA gives me 3,3V - this 366Ohm. So, using 370 Ohm resistor I will get 1,48V at the level 0 (4mA) and 3,14V at the level of 1,4m. Surely I am ā€œloosingā€ the 0-1,48V range and my accuracy drops down.

1 Like

Thanks for the advice,
On the site you found, they indeed connect the Vout- to the converter and have the Vout+ go trough the sensor.
I have been following the schema on the site of DFrobot where they have the Vout+ connected to the converter and the Vout- to the sensor. That could indeed explain the reason my converter catches fire.
My DFRobot current to voltage converter arrived today. I assume I should still connect this one to the Vout+ right (and have the Vout- go trough the sensor and then to the converter), as is depicted on the schema on the DFRobot website?

Looking forward for your experience with DFrobot.
IMO as lomg as you are using completely separate power for sensor than it should not matter where you connect the sensor (either between Vcc and + connector, or GND and - connector - keeping in mind sensor + and -). The chalenge starts when you use setup-up module which (in most cases) hard connects GND of input and output. In that case you can galvanic connection between your sensor power GND and module power GND which has to be taken in consideration.
I woudl first check if ā€œ-ā€ connector of module input is connected to GND of module power supply (as it was in the other module). And in case it is, I would connect sensor between Vcc and + input of module. It should not matter for the sensor as it ā€œcreatesā€ current as a result of itā€™s measure and you are safe that GND of sensor power supply is connected to

1 Like

Iā€™m in the situation where I use one power supply that provides 5V to most of my devices and powers a step-up power supply that delivers the 24V.

I can confirm your statement about the cheap converter: the resistance between GND and the - on the current sensing part is 0.00 Ohm.

For the more expensive DFRobot converter, the resistance is 0.2 Mohm (200 000 Ohm).

I really want to avoid destroying the DFRobot one. Given that the GND and - are not connected, how would you suggest I connect the converter to the sensor and step-up power supply?

This is good sign - meaning that module is more ā€œsecuredā€. IMO there should be no difference in connecting sensor either to Vcc od GND of step-up board. At the same time I think it is always ā€œmore safeā€ to connect it between Vcc and + of the module (in case the GND matters and knowing that GND of your step-up module is connected to GND of power supply).

1 Like

OK so I connected the DFRobot converter according to your suggestions and it works fine!
I then also connected the cheap converter with the burnt ā€˜current signal sampling resistorā€™ in the same manner and it works fine too!
I also have a brand new version of this cheap converter nowā€¦

So I now have the luxury problem that I need to choose between the DFRobot and the cheap converter.
The cheap one has the benefit that I can set for which mA it should output 0V and for which mA it should output 3.3V. It also has many more components on it, which as a layman I would assume means its fancier.

But my number 1 criterium is safety (e.g. not catching fire), I guess the DFRobot one wins in that front, though I have not (and will not) connected it in the ways that made the cheap converter smoke/catch fire.

Which one would you pick?

Thanks a million for all the advice you have given, I donā€™t think I would have figured it out without you!

I integrated it into Home Assistant today and to my surprise the ESPHome code I had written weeks ago works :smiley:
So I figured I might as well share it here (not claiming there arenā€™t better ways of doing it).
Important note is that this code is for when you are using an ESP8266 in combination with an ADS1115 analog to digital converter (costs ā‚¬1 or so and is much more accurate than the built-in ADC in the ESP8266). Slight adjustments would be necessary if you use an ESP32 or donā€™t use the ADS1115.
Hereā€™s the diagram of how I connected everything (a bit messy as I changed it a lot based on the helpfull instructions of @Maco65.

And hereā€™s the code:

# setup ic bus
i2c:
  sda: 4 #for the ESP8266, most often 21 for the ESP32
  scl: 5 #for the ESP8266, most often 22 for the ESP32
  scan: True
#  id: bus_a #I believe this is necessary for the ESP32, but I'm using the ESP8266

# define the ads1115 analog to digital convrerter on the bus
ads1115:
  - address: 0x48 #This is the address used by the ads1115 if you connect ADDR with GND on the board or if you don't connect it to anything. Other addresses can be chosen (if this one is occupied allready) by making a diferent connection.
#    i2c_id: bus_a #This is probably necessary on the ESP32, the way I'm doing it might be incorrect, but in any case it's not necessary for me as I'm using the ESP8266

#These sensors assume one circular tank with the same radius along it's height. I will connect a second tank and to solve that issue I will create additional sensors and sum these with the original sensors into new Total sensors. I need to look at the usable height in the second tank (minimum water level when the siphon connecting the two tanks will start working, assuming that the inlet ofthe pump in the main tank is placed lower than that). I will then define the measured voltage at that level as 0cm. I then need to know the voltage when the second tank is at it's maximum height (i.e. when water in the main tank will start flowing to the drainage citern). I can then do the lineair calibration. Now I have the centimeters. Summing these centimeters with the other one is meaningless. For the liters sensor I need to know the surface mĀ² of the new tank and multiply it with the new height sensor. That result I can indeed sum with the liters of the other tank into a new total. To create the percentage sensor I need to sum the new total liters sensor by the sum of the max liters of both tanks.
sensor:
  - platform: ads1115
    multiplexer: 'A1_GND'
    gain: 4.096
    id: watertank_voltage
    name: "Water Level Sensor Voltage"
    icon: 'mdi:water-well'
    unit_of_measurement: 'V'
    update_interval: 1s #the delta filter will ensure it only sends values when something changes. 
    filters:
      - sliding_window_moving_average:
          window_size: 10 #creates a moving average of the last 10 values
          send_every: 1 #sends the moving average at every measurement (but only if it passes the delta filter below)) 
          send_first_at: 1 #after startup immediately start sending the result rather than wait for the first 10 measurements
      - delta : 0.0015 #only send the result if the voltage difference with the last sent result is higher than this
  - platform: template
    name: "Water Level Sensor usable CM" #first X cm are below pump inlet and thus unuseable.
    id: watertank_cm
    icon: 'mdi:water-well'
    unit_of_measurement: 'cm'
    lambda: |-
        return id(watertank_voltage).state;
    update_interval: 1s #the delta filter will ensure it only sends values when something changes. 
    filters:
      - calibrate_linear:
          # Measured value of X volt maps to y cm
          - 0.0 -> 0
          - 2.5 -> 165.0
      - delta : 0.001 #only send the result if the difference with the last sent result is higher than this
  - platform: template
    name: "Water Level Sensor usable %"
    id: watertank_percent
    icon: 'mdi:water-well'
    unit_of_measurement: '%'
    lambda: |-
        return id(watertank_cm).state / 165.0 * 100; 
      #divide by max water level height to get a percentage
    update_interval: 1s #the delta filter will ensure it only sends values when something changes. 
    filters:
      - delta : 0.001 #only send the result if the difference with the last sent result is higher than this
  - platform: template
    name: "Water Level Sensor usable liters"
    id: watertank_liter
    icon: 'mdi:water-well'
    unit_of_measurement: 'l'
    lambda: |-
        return id(watertank_cm).state / 100 * 3.14159265 * 1.13751599 * 1.13751599 * 1000.0;
      #height (meters) times pi times radius (meters) squared times 1000 gives liters.
    update_interval: 1s #the delta filter will ensure it only sends values when something changes. 
    filters:
      - delta : 0.001 #only send the result if the difference with the last sent result is higher than this

The code is not ideal in that it only sends the Voltage/Cm/Liters/% to ESPHome when there is a change. I would like to to also send the value every hour or every day or so even when there is no change (but send the value immediately if there is a change). I had tried adding the filter - heartbeat : 60m to accomplish this but it creates a very illogical behaviour. The result is that my delta filter is completely ignored and it just sends the value every hour and does not send any values anymore in between those periods even if there is a change.

So it seems like you have to choose between

  • either sending the values at a regular interval (but then you wonā€™t immediately be notified of a change) like every 5 minutes or so.
  • doing the measurements very frequently (e.g. every second) so that Home Assistant immediately is notified of a change, and then prevent spamming home assistant using the delta filter (but then Home Assistant wonā€™t get any values when there is no change for days for example).

I could not find a solution to this, if anybody has a solution, thatā€™s very welcome.

8 Likes

Thank you for that. I got my ADC, but the sensor is a month in transit with no telling when it may arrive. I recognize the D1, ADC, sensor, and buck convertor, what is the other component used?

Itā€™s the cheap current to voltage converter I purchased from Aliexpress.
I also have the more expensive DFRobot one. havenā€™t figured out yet which one I will use in the end. Any advice on that is welcome :slight_smile:

Happy that you have now luxury to choose from! :slight_smile:
To pick one or the other I would consider:

  1. safety. Although the fire in your case IMO is related to the way power is provided still DFRobot seem to be better as itā€™s input terminals does not seem to be connected to either GND or Vcc of the module. So here + for DFRobot. From other hand if you have connected it the way it works I think there is no risk now that it catches the fireā€¦
  2. Power supply impact. In the link I have mentioned earlier it was clearly stated that checp module is sensitive for power supply volatility. I could not find any information how DFRobot is reacting. Would be nice to test what happens with Vout if the water level i s the same but Power supply changes from lets say 5V to 4V. In case the Vout is stable then this will be a BIG + for DFRobot
  3. DFRobot based on product Wiki produces Vout between 0,48 and 2,4 V for currents between 4 and 20 mA. This makes effective Vout range of 1,92 V for measurements. In case your tank is not going to be filled with ā€œfull sensor capacityā€ (I assume 5 meters) the range is getting even smaller. Cheap module can be regulated that for your specific sensor measures (this is my case when I expect min 4mA and max 10mA) you can have full ESP8266 scale used (from 0 to 3,3V).
    So, here the + is for cheap module

Maybe you can connect one for few weeks and then the other and see the difference ? :wink:

It seems that in case you have very stable power supply (5V) and max level of your tank will be much less then 5m, the cheap module has advantages for the range and thus for accurancy. If not, and stability of measures over time are important (and provided that DFRobot conversion is not affected by changes in Power supply) then DFRobot seem to be better choice.

Let us know which one you use and how are the results.

As usual your advice is extremely helpful.

I tested the cheap converter with two different USB power supplies, one outputs 5.21V, the other 4.95V
The output voltage of this cheap converter is 0.597V in one case and 0.708V in the other case.

I then did the same with the DFRobot converter, and the output was 0.668V in both cases.

I could also clearly notice that there was less variation over time in the output voltage.
The DFRobot varies about 0,004V, while the cheap converter varies about 0.008V over time. EDIT: I realise now that I did these tests with the converter that caught fire, so this is not a fair comparison.

So these are strong arguments in favour of the DFRobot converter. It means that you just need to calibrate the voltage to the minimum and maximum levels of the water tank once, while with the cheap sensor if something happens (e.g. you change the power supply), you have to recalibrate.

The downside is as you mention the fact that it can only has an effective Vout range 1,92V for measurements.

Further measures I took to increase accuracy: A higher precision dedicated ADC + my pressure sensor has a range of 2 meters.

I wanted to see how accurate my measurements are with the DFRobot sensor.
Iā€™ve set-up these filters:

    filters:
      - sliding_window_moving_average:
          window_size: 10 #creates a moving average of the last 10 values
          send_every: 1 #sends the moving average at every measurement (but only if it passes the delta filter below)) 
          send_first_at: 1 #after startup immediately start sending the result rather than wait for the first 10 measurements
      - delta : 0.0015 #only send the result if the voltage difference with the last sent result is higher than this

With delta set to 0.0015 I get the impression I donā€™t often get new results due to the random variation in the voltage.
I did a test by slowly adding water in a bucket until I got a new result (0.67120V).
Then I again slowly added water until another new result came in (0.67280V). To achieve this I had to raise the water level by about 0.17cm of water, which for my water citern would mean about 7 liters of water. Thatā€™s a pretty good accuracy :slight_smile:, enough to detect a toilet flushing!

Some math using the above measurements using the effective Vout range of 1,92V (discussed in our previous posts) confirms that these results make sense:
0.17cm/(0.6728V-0.6712V)*1.92V=204cm and my pressure sensor has a measurement range of 200cm!

In conclusion: Iā€™m going to use the DFRobot converter

Searching on Aliexpress I see that they have a sensor (QDY30A) that comes in different versions.
Providing either 4-20mA, 0-5V, 0-10V or even RS485 output.

The 0-5V version combined with a ADS1115 seems to be a very simple solution.

Does anyone have any experience with this sensor?

1 Like