Hey guys, I bought a capacitive soil moisture sensor and wanted to operate it on a wemos d1 mini via esphome, but it doesn’t seem to work. I inserted the adc platform in esphome and took pin A0. It now always gives me the value 0.00391v regardless of whether I have the sensor wet or dry. I’ve tried it on 3.3v and 5v but always the same. Has anyone already made experiences with the soil moisture V2.0? Or do I have to use an adc converter?
Make sure your pins are all connected, and that there is not filters on your data output see this tut below for pins (theres a d1 wemos listed) and simple code to read voltage. atm i have like 3 diff types of moisture sensors and 2 more otw. The 2.0 one you linked is pretty good after you calibrate it.
Thanks for the helpful link @ljohnso16 . I did it according to these instructions, but it only shows me the value 3.0, regardless of whether it is dry or wet. I think the sensor doesn’t seem to work properly. I ordered the sensor from Aliexpress.
On the esp32/D1 in esphome you have to put “attenuation: 11db” for the adc platform, esp8266 you dont, this is also overlooked a lot, make sure your esphome yaml has it included. Heres a SS of my yaml. i use a esp8266 so i dont have “attenuation”. I am still working on its calibration/seeing if i even wana bother(ive tried making the window larger and smaller and its not cleaned up the data much)
Also its possible it was a bad sensor board.
For the money and ease of use i would recommend this board(LILYGO®TTGO T Higrow ESP32 WiFi And Bluetooth Battery DHT11 Soil Temperature BEM280 Humidity Photometric Electrolyte Sensor|temperature and humidity sensor|temperature and humiditybatteries batteries - AliExpress, its a lot more expensive then a moisture board and a d1). Has a lot more sensors, and gives more consistent data.
The image below shows a sample of a plant drying out and then being watered and clearly the info is all over the place.
Hi Stefan, did you get this working? I think about to work with this as well.
Thanks for feedback. I can also confirm, it works for me as well!
@ljohnso16 I used your code to setup my capacitive sensor together with EZDelivery ESP8266 (Wemos D1 Mini clones). But all I can get is this:
I cant get any values from the sensor, neither any entity on ESPHome integration (only device). Tried both with 3V and 5V. Any ideas for what I’m doing wrong?
Thanks in advance for any help.
Here is my code:
esphome:
name: soil-moisture-inside-garden
platform: ESP8266
board: AZDelivery_d1_mini_nodemcu
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Soil-Moisture-Inside-Garden"
password: "my_pass"
captive_portal:
# Enable logging
logger:
# Enable Home Assistant API
api:
encryption:
key: "my_key"
ota:
password: "my_password"
sensor:
- platform: adc
pin: A0
name: soil_moisture_inside_garden
id: moisture1
accuracy_decimals: 4
update_interval: 1s
unit_of_measurement: "v"
icon: "mdi:water-percent"
filters:
- median:
window_size: 20
send_every: 10
send_first_at: 5
# - calibrate_linear:
# - 0.0175 -> 0
# - 0.0488 -> 100
#updates above template to HA #
interval:
- interval: 10sec
then:
- component.update: moisture1
UPDATE: I tried out also with a original Wemos D1 Mini and another sensor, and a still have no readings…
UPDATE 2: The error Im getting:
Logger: frontend.js.latest.202207071
Source: components/system_log/__init__.py:190
First occurred: 15:09:59 (16 occurrences)
Last logged: 16:18:23
:0:0 ResizeObserver loop completed with undelivered notifications.
Hi sergioxavier, it’s a long time ago since you asked and I’m also trying to get it run but are you sure the board name is correct? The name you used is not listed in the list of possible names:
board list
Hi I got a problem updating, I get a message
" Pin 17 is used in multiple places."
is there any solution?
Yes, stop using GPIO17 in many places. And seriously… attach your code.
sorry, you are right, this is the message I get:
Failed config
output.gpio: [source /config/esphome/moisture.yaml:41]
Pin 2 incorrectly sets allow_other_uses: true.
platform: gpio
id: light_output
pin:
number: 2
allow_other_uses: True
mode:
output: True
input: False
open_drain: False
pullup: False
pulldown: False
analog: False
inverted: False
inverted: True
and this is my code (moisture)
sphome:
name: moisture
friendly_name: moisture
platformio_options:
board_build.f_cpu: 160000000L
esp8266:
board: esp01_1m
...
captive_portal:
web_server:
port: 80
light:
- platform: binary
name: "Blue Light"
output: light_output
id: led_light
restore_mode: ALWAYS_OFF
output:
- platform: gpio
id: light_output
pin:
number: GPIO2
allow_other_uses: true
inverted: true
sensor:
- platform: adc
id: "adcMoisture"
pin:
number: A0
allow_other_uses: true
accuracy_decimals: 5
unit_of_measurement: '%'
filters:
- calibrate_linear:
- 0.00488 -> 100.0
- 0.00391 -> 0
name: "Plant - Moisture Level"
update_interval: 30s
- platform: adc
id: "adcRaw_Sensor_Data"
pin:
number: A0
allow_other_uses: true
accuracy_decimals: 5
name: "Plant - Sensor Voltage"
update_interval: 30s
- platform: wifi_signal
name: "Plant - WiFi Signal Sensor"
update_interval: 30s
- Why do you set
allow_other_uses: True
forGPIO2
? I see only one use of this pin in your code. - You are using
esp01
, which has no (?) analog port.
- because I got this message:
sensor.adc: [source /config/esphome/moisture.yaml:48]
Pin 17 is used in multiple places.
platform: adc
id: adcMoisture
pin:
number: 17
mode:
analog: True
input: True
output: False
open_drain: False
pullup: False
pulldown: False
inverted: False
accuracy_decimals: 5
unit_of_measurement: %
filters:
- calibrate_linear:
datapoints:
- from: 0.00488
to: 100.0
- from: 0.00391
to: 0.0
method: least_squares
name: Plant - Moisture Level
update_interval: 30s
disabled_by_default: False
force_update: False
device_class: voltage
state_class: measurement
raw: False
sensor.adc: [source /config/esphome/moisture.yaml:60]
Pin 17 is used in multiple places.
platform: adc
id: adcRaw_Sensor_Data
pin:
number: 17
mode:
analog: True
input: True
output: False
open_drain: False
pullup: False
pulldown: False
inverted: False
accuracy_decimals: 5
name: Plant - Sensor Voltage
update_interval: 30s
disabled_by_default: False
force_update: False
unit_of_measurement: V
device_class: voltage
state_class: measurement
raw: False
- I don’t understand the question
I don’t understand at all what you are trying to do.
You had the error on Pin17, so you set allow_other_uses for Pin2? I don’t understand this.
ESP01 doesn’t have PIN17 at all, nor does it have an analog port. You can’t connect this sensor to the ESP01. Look for an ESP12F, which has an ADC port
You also know that you dont need to add configuration options that are by default Off already and you dont even need. Adding a bunch of excess configuration just to make it look sophisticated doesnt impress anyone. Just learn how to use the basics of a gpio and not using 1 in multiple places and then play with the non essential options.
Here you have used inverted: twice and on one you set it to True while the other one is False. Your also using AO 3 times…