4-20mA Liquid Level Transducer and NodeMCU YAML Calcuations

I am attempting to utilize a 2-wire 4-20mA pressure sensor for our rain catchment cistern. I currently have the sensor setup in ESPHome on HA and wired up (I believe correctly). I am seeing data via HA. However, I cannot figure out what data I am seeing and how I can convert it to pressure and then into water volume. I am rather new to all of this and have no formal education in electronics. I am telling myself that this is just an opportunity to dive in and try and learn through the process. I am enjoying the challenge and find myself motivated to try and learn.

  • This is the sensor I am attempting to use. It is currently dropped into a ~18.9 L water jug. I am powering the sensor with a 12v 2A wall unit. The NodeMCU is powered via the computer (5v USB). I have it wired up as follows (I’m not sure if I need to draw on this to clarify?). The lower set of terminals is the pressure sensor. There is a single 150 ohm resistor on the positive. The top terminal is just a Dallas temperature sensor. It is working correctly.

  • My YAML for the sensor is as follows:
   # 4-20mA Drop-In Transducer (Pressure)
  - platform: adc
    pin: A0
    name: "Stone Cistern Water Volume"
    id: water_volume
    icon: "mdi:water-percent"
    update_interval: 5s
    raw: true
    accuracy_decimals: 2
    filters:
      - multiply: .01
  • With this set-up I receive the following in the log:

    [09:31:54][D][sensor:126]: 'Stone Cistern Water Volume': Sending state 3.02000 V with 2 decimals of accuracy
    

I have spent quite a bit of time scouring the internet for ideas or other examples. This is how I came upon the wiring solution.

Can anyone provide any guidance as to how I can get a volume number from this sensor? I believe that I need to read A0, which should be a number between 0 and 3.3V from the sensor. I need to figure out how this relates to the pressure reading from the sensor, take that pressure reading and plug it into a volume calculation (lambda and a template?) that utilizes the base dimensions of the tank, and then calculate actual volume from there.

I am stuck at converting the Voltage reading to a usable value and would appreciate any guidance…assuming the reading I am getting is valid?

I see the sensor needs 12 - 32v dc. I understand you need a resistor to ensure you have the correct output.

  1. With no pressure, use a multimeter and measure the voltage output of the sensor. Then go to max pressure and measure the voltage again AND with a tape measure record depth. Check it is not more than 3.3v. All good
  2. Repeat again but record the volts measured by the ADC; SO that should be 0 m and say 3 m voltages
  3. Use a filter; linear calibration 1 to 0 (that is 1 v to 0m depth say) and then second line is 3 to 3 say
  4. Check that gives you correct depth in m
    5 if that works use filter multiplication to get volume. I had to write custom lambda because I had a cylinder on its side

Thank you so much for your detailed response JulianDH. I appreciate your taking the time to respond.

Is it possible to do this without needing a maximum measurement? As this cistern is for rain catchment I cannot feasably fill it full just to take a measurement. The cistern I plan to use this on is a 15,100L stone cistern that is around 3m tall. We have some other cisterns that are smaller, at around 9,500L and 2.5 m in height that are currently full and could be used to gather that data point.

Currently, without any pressure, when measuring across the + and - terminals of the sensor directly, I see 11.52v (I am using a 12v power supply and a 150ohm resistor). When I drop it into 0.381 m of water in a jug I have here I see 11.25v.

When I measure across the ADC (A0 and NodeMCU ground) I see 0.622V when no pressure and .905V when the sensor is in the 18.9L jug.

Since I am not seeing 3.3V at the sensor I am unsure where my problem may lie?

Sorry for slow response

Is it possible to do this without needing a maximum measurement? As this cistern is for rain catchment I cannot feasably fill it full just to take a measurement. The cistern I plan to use this on is a 15,100L stone cistern that is around 3m tall. We have some other cisterns that are smaller, at around 9,500L and 2.5 m in height that are currently full and could be used to gather that data point.

The great thing about this is that you can update the linear calibration with as many data points as and when you can. i.e. when the cistern is next full. When the cistern is full, pre-measure the full height and observe the voltage reported by the ADC (ADS115) in the ESPHome dashboard logs. Add the new data to linear_calibration when you can.

Can you confirm the preset range of the pressure sensor? So my pressure sensor is 0 - 5 m. I obtain a voltage of 0.028v at 0m and 2.275volts at 1.98m. You can add more than this to make it more accurate.

Remember your voltage can not be MORE than the voltage of your ADC (what ever you are using).

1 Like

I think I have everything hooked up properly but now I get a reading of 1024 on the pressure sensor no matter if it is in water or out. Should I take that to mean my sensor is bad or that I have crushed the breathing tube for the atmospheric pressure?

From memory 1024 is the maximum output of ESP8266 ADC. I thought the sensor was max 5v in which case you should be going through a ADS1115 that can handle the higher voltages. I would measure voltage with multimeter before you do anything.

I have a similar setup using a 4-20mA sensor which sits in a water tank that takes the rain off our garden building. This then drains into the mains via a long hose. I use it to monitor that the tank is not over filling and does drain down. This is integrated into HA via mqtt.

Didn’t use esphome but wrote some custom code on a M5Core2 (about 5 years ago), which is basically an ESP8266 with a screen in a nice case.

To interface the sensor i used a 4-20ma to i2c convertor. This handles all the voltage differences and provides a digital output to read on the esp8266. This might be easier to use to interface into your esphome device. I thwn just cailibrated it using one of the wifes flower vases!

I use one of these but they look very expensive now. Cant remember how much i paid but dont think this much.

I also found this which is much cheaper but not tried it.

Would say the setup has been 100% reliable and accurate.

I have a DFRobot Gravity ADS1115 connected and an analog to voltage converter on hand if it is a better solution? If I am understanding things correctly, the ADS1115 will help with fluctuations in readings by providing a higher resolution, correct?

I think I have the ADS1115 connected correctly, but I am unsure. With 12v in for the pressure sensor I am seeing 3.43 at the sensor. The switch is set to 0x48 on the ADS1115. I do not have anything connected to A0 on the ADS1115. I am wondering if I should and if that is where my problem lies?

When I flash the YAML for ESPHome I see the following:

[ads1115:074]: Address: 0x48
[ads1115:076]: Communication with ADS1115 failed!

My YAML is as follows (from this post):

# i2c Component
i2c:
  sda: GPIO5
  scl: GPIO4
  scan: true
  id: bus_a
ads1115:
  #  continuous_mode : on
 - address: 0x48
   id: ads1115_48
   i2c_id: bus_a

sensor:
# Gravity ADS1115 Module reading 4-20mA Drop-In Transducer (Pressure)
  - name: "Tank 1"
    id: ads1115_48_a0
    ads1115_id: ads1115_48
    multiplexer: 'A0_GND'
    update_interval: 5s
    gain: 6.144
    platform: ads1115
    unit_of_measurement: "V"
    icon: "mdi:gauge"
    accuracy_decimals: 2

Do you mean you are measuring 3.43 volts from the sensor using a multimeter?
If so is that to show a certain depth? Full/ half-full??

On set up you are looking to your log to show you what i2c devices have been found. This is the important bit as the ADS1115 is a i2c device and needs to be found by on the start scan of the i2c platform. You do not need anything connected to the ADS111 yet just need to make sure it is properly connected to your ESP board. So my logs show me two devices below of which the second is the ADS1115. Once you have it set up and working then we can connect wires to it.

[20:41:27][I][i2c.arduino:069]: Results from i2c bus scan:
[20:41:27][I][i2c.arduino:075]: Found i2c device at address 0x44
[20:41:27][I][i2c.arduino:075]: Found i2c device at address 0x48

Have you read the set up notes on ESPHome?

also using a similar setup. Here’s a thread from 3 years ago on it:

Includes my YAML as well.

1 Like

If you mean a current to voltage converter, then yes you should be using that between the sensor and an adc. These sensors vary their current output not their voltage, so if what i see in your photo is a voltage bridge, you will never get a correct reading from this.