0-5V Water Level Sensor + ESP32

Hi, I'd like to measure the water level in a well. I purchased this sensor with a 0-5V output and connected it to ESP32 with ESPHome.

Unfortunately the measured voltage looks like this:

The sensor requires 24V DC, but I read it works fine with 10-30V, so I connected it to a 12V DC adapter I had. The output is 0-5V and I read ESP32 can only manage 3,3V so I used two resistors as voltage dividers before connecting it to GPIO 32. ESPHome configuration looks like this:

  • platform: adc
    pin: 32
    name: "Napięcie czujnik ciśnienia studnia"
    unit_of_measurement: "V"
    attenuation: auto
    update_interval: 5s

The distance from the well to the ESP32 in my basement is about 30 meters. When I connect the sensor with a 30 meter cable I get some small 0,1V spikes. When I connect via 10m, the spikes are bigger - around 0,3V.

I'm not sure where the issue lies and how to narrow it down. Could be faulty sensor, cable length, too low sensor voltage, incorrect esp32 connection, not really sure.

Does my connection and the components I used make sense? Would really appreciate some help, thanks!

That wire is an antenna, one length pics one wavelength. Anyhow you could place Esp next to the sensor?

I have nothing against Polish, but I just don't understand any.

..... not sure what to reply to this :smirk:

If the sensor is analog, what do you read from it with a multimeter, both with and without the voltage divider?

1 Like

I have nothing against Polish, but I just don't understand any.

sorry, I corrected the link to point to the US version :blush:

The sensor requires 24V DC, but I read it works fine with 10-30V
..... not sure what to reply to this :smirk:

This could be the issue, but there's a lot of Aliexpress offers with this sensor model QDY30A-B and they have this in the specs: power supply is DC24V (DC10-30V can be used). To test it I'd need to buy another adapter, so wanted to check other things first :slight_smile:

If the sensor is analog, what do you read from it with a multimeter, both with and without the voltage divider?

I'll double check

That wire is an antenna, one length pics one wavelength. Anyhow you could place Esp next to the sensor?

I can try connecting it directly with the 4m cable the sensor came with and see if there's a difference. Is 30m too long for an analog sensor?

Is the flat line below 0.1V correct? If so you can make a moving-average and add some "fuzzy logic" to throw-out the spikes.

Smoothing/averaging can help to filter the noise, but if all of the noise is in one direction you'll be left with a biased average.

A capacitor at between the ESP's analog input and ground may help to filter-out the spikes. Try 0.1uF. Or, with the voltage divider there's no danger of the capacitor "loading" the sensor's output so you can use a bigger capacitor for more filtering.

If you'll never need the full 5V range an over-voltage protection circuit might be better than a voltage divider. It will give you bigger readings and more resolution. (Of course it will also make the spikes proportionally bigger.)

1 Like

Thanks for the hints, I was also thinking about removing the voltage divider, since the water will never be that high. The flatline is what's reported if there's nothing connected, I guess it should be zero, instead of 0,1v.

One thing I don't understand is why are there such spikes, instead of a constant line. I understand this isn't normal for an analogue sensor, right?

Try that, even 4m is a long wire though.
30m is big antenna, it likely collects interferences.

Ok, thanks. And If I need the 30 meters distance, then what can I do? This sensor is also sold in 4-20 mA and RS485 versions. Can one of those work over 30 meters and ESP32? I can also put ESP32 inside the well, but there's a lot of humidity there and problem with wifi.

1 Like

Is it possible to make an improved diagram, with all wires? I suspect there's more clues in a complete diagram. And the voltage divider, is it sensor -> 20 k - ESP32 - 10 k - GND or the opposite?

RS485 would be a good bet.

there are more wires, because there's also a water flow sensor and temperature sensor connected, but in theory they are unrelated :slight_smile: I can do some more testing with a bare esp32. But I previously had a different sensor connected to the same voltage divider and the diagram back the looked much better:

And I checked with a multimeter that the voltage was around 0,5V and behind the voltage divider ESP32 reported around 0,3V. 20kOhm is first as in the digram.

Tomorrow I'll check direct 4m connection with an empty ESP32 and just the 0-5V output to GPIO 32. Hopefully I won't fry ESP32 If I only put the sensor 10 cm under water for minimal output voltage :slight_smile:

Voltage got amplified? How's that possible. You must mean 5 / 3.3 V or 0.5 / 0.33 V.

Edit: Thanks :upside_down_face:

Yeah, sorry typo, I meant 0,3V as in the screenshot I pasted.

Both are better for long wiring.

3 Likes

It looks much better now, and that initial spike is probably just from initializing, you could add a certain delay after the initial peak, and after that average the readings.

About the sensor itself and the way it measure, I'm just throwing in the possibility that it could be sensible to induced pressure waves in the water like sound, hence spikes in the readings.

Perhaps this was already answered and I missed it.

Is there a common ground between the sensor and the ESP?

and if you do then it's another problem you can debug.

but I read it works fine with 10-30V

Not likely since you would need greater than 10V for the 10V output version.

FYI:
The ESP32 ADC accuracy is very poor and has a limited range. The input range is only 0.15V to 3.1V

Is there a common ground between the sensor and the ESP?

There isn't. Should there be one? Should I connect gnd of esp32 to V- on my power adapter?

The 12V adapter is currently in my zigbee irrigation controller cabinet that I built

The ESP32 is in a separate box, but I guess I could move/connect the two. ESP32 is separate because it's close to a flow meter on a pipe and initially I had a different pressure sensor that was 5V and I powered it directly with ESP32 without any power adapters. A shop recommended it to me, but I later read it's not submersible.

Not likely since you would need greater than 10V for the 10V output version.

Yeah, that's a good hint. I ordered a 24V adapter, should arrive tomorrow for testing, hopefully that's it.

I'm thinking about buying a multimeter e.g. this one to be able to check the output voltage instead of connecting it to ESP32 and do some tests connecting the output directly and via a 20m cable to check what's the difference. That multimeter has a oscilloscope, so maybe I can also see some simple short lived charts there of voltage changes.

Connect the ground of ESP32, ground of sensor and power supply negative together.

Note about the ESP range

2 Likes