I have similar ones. I integrated them with an ESP8266 board using ESPHome.
Basically, the output of this sensor will be converted by the ADC to a value between 0 V and 1 V. To calibrate it, I captured the value on a “dry” and a “wet” (freshly irrigated) soil. The two obtained values are 0.82 V and 0.36 V, respectively.
Logs from ESP8266 (when it is placed in a dry soil)
[adc:104]: 'Soil Moisture': Got voltage=0.82V
Logs from ESP8266 (when it is placed in a wet soil)
[adc:104]: 'Soil Moisture': Got voltage=0.36V
Finally, I used the fuction calibrate_linear
to convert the ADC value to a “human readable one” between 0 and 100%:
sensor:
- platform: adc
id: soil_moisture
pin: A0
name: "Soil Moisture"
unit_of_measurement: "%"
device_class: humidity
accuracy_decimals: 1
filters:
- calibrate_linear:
- 0.82 -> 0
- 0.36 -> 100
update_interval: 20s
PS: You can also use the following lambda
instead of the calibrate_linear
:
filters:
- lambda: |-
float moisture_dry_soil_value= 0.82;
float moisture_wet_soil_value = 0.36;
if (x > moisture_dry_soil_value ) {
return 0;
} else if (x < moisture_wet_soil_value) {
return 100;
} else {
return (moisture_dry_soil_value - x) / (moisture_dry_soil_value - moisture_wet_soil_value ) * 100.0;
}
After flashing this config to my ESP8266:
# The raw ADC value
[01:25:40][D][adc:104]: 'Soil Moisture': Got voltage=0.49V
# The converted Value
[01:25:40][D][sensor:121]: 'Soil Moisture': Sending state 71.68818 % with 1 decimals of accuracy
# (0.82 - 0.49) / (0.82 - 0.36) * 100 = 71.6888.....
I know that it is not 100% accurate (and never will be the case), but at least I have an idea about the moisture level of the soil. I highly recommend you to watch the variation of this value for some weeks and re-calibrate your sensor… Then you can define the % threshold under which you have to automatically trigger the irrigation system .
Peace!