Resistive soil moisture readings

I’m planning on using a couple of these sensors

image

They are well known for their “capacity” to get corroded when constantly energized. To avoid this and extend their lifespan, some Arduino or RPi implementations use an interval reading (IE: every 20 minutes).

I’m using an ADS1115 DAC with a Wemos D1 mini to get the analog reading into HA. Like so (just reading the voltage for now):

sensor:
  - platform: ads1115
    multiplexer: 'A0_GND'
    gain: 6.144
    name: "ADS1115 Channel A0-GND"

There’s an option update_interval option for the ADS1115 component:

That’s interesting, but not sure if that will make the ESP module read the analog value every x seconds, while the probe is constantly energized (which I want to avoid) or both. Assuming this will not be the case, but well, I just wanted to make sure.

TIA

I used one of these a few years ago. What you need to do as power it from an output on the ESP so you can completely turn it off when not taking samples. Simply changing the update frequency doesn’t achieve the goal.

You can then create an internal ESPhome automation to cycle the output and power the probe on for say 60 seconds every 10 minutes or whatever timeframe you choose.

When the probe has no power you will get some crazy value as the analogue reading so need to include a filter to stop that coming through to ruin your readings.

Get the capacitive sensors instead of the resistive ones. They are less prone to corrosion though the electronics needs some waterproofing: Waterproofing a Capacitance Soil Moisture Sensor : 11 Steps (with Pictures) - Instructables

2 Likes

Interesting workaround! But since the price of the capacitive sensor is so low, I think I’ll go with a couple of those :wink:

I think you’re right. I will avoid headaches… BTW, nice work on waterproofing! :+1: :

While I wait for the capacitive sensors (which use a different method, but output an analog signal), I’m trying to convert the voltage reading from the probe to percentages.

Tried with this code, but I get negative results :thinking:

sensor:
  - platform: ads1115
    multiplexer: 'A0_GND'
    gain: 6.144
    name: "Sensor humedad bancal 1"
    update_interval: 60s 
    filters:
      - calibrate_linear:
          - 0.0 -> 100
          - 5.2 -> 0

Voltage values range from 0v (100% humidity) to 5.2v (dry)

Hi.

If you get a raw value higher that 5.2 volt that will result in a negative value.
So what it the raw value from the logs is a good start.

/Mattias

This is what I get in the logs:

[15:16:20][D][ads1115:163]: 'Sensor hum bancal 1 (v)': Got Voltage=5.346750V
[15:16:20][D][sensor:099]: 'Sensor hum bancal 1 (v)': Sending state 1.02404 V with 3 decimals of accuracy
[15:16:25][D][ads1115:163]: 'Sensor hum bancal 1 (v)': Got Voltage=5.344687V
[15:16:25][D][sensor:099]: 'Sensor hum bancal 1 (v)': Sending state 1.06370 V with 3 decimals of accuracy
[15:16:30][D][ads1115:163]: 'Sensor hum bancal 1 (v)': Got Voltage=5.347312V
[15:16:30][D][sensor:099]: 'Sensor hum bancal 1 (v)': Sending state 1.01321 V with 3 decimals of accuracy

And the ESP code for the sensor:

sensor:
  - platform: ads1115
    id: moisture_sensor_1_volts
    multiplexer: 'A0_GND'
    gain: 6.144
    name: "Sensor hum bancal 1 (v)"
    unit_of_measurement: 'V'
    update_interval: 5s
    filters:
     - calibrate_linear:
       - 0.2 -> 100.0 # low value means the soil is swamped
       - 5.4 -> 0.0 # high value means the soil is dry

On the UI, I’m getting values of around 1v (the value shown in the state section of the logs) :thinking:

It seems reasonable according to the linear calibration you have said.

The raw value is 5.34 and you had said to the linear calibration that 5.4 should be zero.

That means that the calculation becomes something like this

-100/5.2*(5.346750-5.4) = 1.02403846154

Which is sent out.

I used a lambda instead. Which is also possible.
It look like this.

sensor:
  - platform: adc
    pin: A0
    name: "Jordfuktighet"
    update_interval: 6s
    filters:
      - exponential_moving_average:
          alpha: 0.1
          send_every: 10
      - lambda: |-
          if (x > 0.8) {
            return 0;
          } else if (x < 0.36) {
            return 100;
          } else {
            return (0.8-x) / (0.8-0.36) * 100.0;
          }

0.36 is when I put the moisture meter in very water drenched soil.
0.8 when I had my meter in the air.
I used the internal adc on my d1. Which is very noisy so I filter it .

/Mattias

1 Like

Not the same quality, but almost there :joy:

That unit in the bottom of the photo will not survive too long, the metal strips will corrode.

Correct. But since I bought some a few months ago, I will use them until they end up in the recycling :man_shrugging:

The sensor only lasted one month of continuous use :man_shrugging:

1 Like

This is why you need to power them up only when taking readings. When I previously used one of those sensors I had the power coming from a digital output of the ESP. The output would be turned on only for 30 seconds every hour of whatever it was I had programmed. That was enough time for the sensor to stabilise and give a reading to HA, then turn off. Having them permanently energised destroys them very quickly as you have discovered.

I bought a few of these.

They come already sealed with housing and batteries.
The chip is a ESP32 S2, so ESPHome and the like can be used.

I had to drill a hole in the housing to get access to the USB-C charging plug though, but I made it shaped so I could buy USB-A protection plugs and use them to “splashproof” it a bit.

I then bought a 5 port USB charger, so I could a group of plants at the same time. It takes a few minutes to be done.

I am currently looking into using ESP-Now instead of Wifi to lower the power usage.

1 Like

Are you still using these sensors? If so I might have two follow up questions: how is your battery life, and how do you interpret the raw values coming from the sensor? (i was using this to get the raw values, wondering what your yaml is like)

Thanks

I am still using mine, but I use MQTT to get them into HA.
I hard code the limit for the sensors into the code by reading the values for totally dry and then for dipped into a glass of water.
These are then used to calculate a percentage that is transmitted.battwry life is around 4-6 months, but I only transmit once a day and use ESP-now to get the power usage as low as possible. This prevents the use of ESPHome though.

Is it possible to use this sensor with Esp01?

A capacitive sensor is not that special, so I see no reason why it can’t be used with other single board computers.
The product I linked to contains the sensor and the ESP32 module on the same circuit board and comes with a case and battery that fit that case.