ESP32 + Soil Moisture and DHT11

I have the following soil moisture reading
Added the below to my ESP32

  - platform: adc
    id: moisture01_v
    pin: GPIO36
    name: "Soil Moisture Voltage"
    unit_of_measurement: "v"
    accuracy_decimals: 0
    update_interval: 3s

ATM it outputs
1.06300 v when dry

When i add it to really wet soil it goes down to .85v but then climbs back up to 1.063 v. What am i doing wrong? tried both of the sensors and boards. Same thing

for my DHT11

  - platform: dht
    model: DHT11
    pin: 13
    update_interval: 60s
    temperature:
      name: "Temperature"
    humidity:
      name: "Humidity"

Works great, but every now and then i will get a nan output. Not sure whats going on there? Loose connection?

[14:15:01][D][sensor:127]: 'Temperature': Sending state nan °C with 1 decimals of accuracy
[14:15:01][D][sensor:127]: 'Humidity': Sending state nan % with 0 decimals of accuracy
[14:24:01][W][dht:172]: Falling edge for bit 39 failed!
[14:24:01][W][dht:060]: Invalid readings! Please check your wiring (pull-up resistor, pin number).

Does it do this if you:

  1. test in a glass of water?
  2. Connect the sensor directly to the esp? (I assume you are using the board in between sensor and esp from your comments?)

If you are using the board, are you using AO or DO? If AO did you tinker with the potentiometer?

My generic first level tests are usually as follows. First things to check are probably all hardware components. Connections and test with a good quality power supply. Then usb cables. Then maybe try your luck with another pin. Then maybe test other esps and sensors if you have spares. Then move on to software.

Ah sorry, using AO and yea tried water, doesnt move much and no have not tried directly to ESP32. Care to explain how :slight_smile:

? :wink:


Yeah went in each direction and let it sit for awhile

1 Like

I’m not totally sure it’s possible tbh.

I’ve used three wire versions like this directly connected.

You could try one wire to gnd and one wire to a adc GPIO.

AU $0.63 48%OFF | Capacitive Soil Moisture Sensor Corrosion Resistant for Arduino Moisture Detection Garden Watering DIY
https://a.aliexpress.com/_mLBqWR0

A bit better reading, but not stable when 100% Dry. BUT better than b4. but confirms i am getting readings

DRY
[16:22:55][D][sensor:127]: 'Soil Moisture Voltage': Sending state 0.15600 v with 0 decimals of accuracy
[16:22:56][D][sensor:127]: 'Soil Moisture Voltage': Sending state 0.13900 v with 0 decimals of accuracy
[16:22:57][D][sensor:127]: 'Soil Moisture Voltage': Sending state 0.23800 v with 0 decimals of accuracy
[16:22:58][D][sensor:127]: 'Soil Moisture Voltage': Sending state 0.09400 v with 0 decimals of accuracy
[16:22:59][D][sensor:127]: 'Soil Moisture Voltage': Sending state 0.09000 v with 0 decimals of accuracy
[16:23:00][D][sensor:127]: 'Soil Moisture Voltage': Sending state 0.37600 v with 0 decimals of accuracy
[16:23:01][D][sensor:127]: 'Soil Moisture Voltage': Sending state 0.55000 v with 0 decimals of accuracy
[16:23:02][D][sensor:127]: 'Soil Moisture Voltage': Sending state 0.20900 v with 0 decimals of accuracy
[16:23:03][D][sensor:127]: 'Soil Moisture Voltage': Sending state 0.11000 v with 0 decimals of accuracy
[16:23:05][D][sensor:127]: 'Soil Moisture Voltage': Sending state 0.09300 v with 0 decimals of accuracy
[16:23:05][D][sensor:127]: 'Soil Moisture Voltage': Sending state 0.15800 v with 0 decimals of accuracy
[16:23:06][D][sensor:127]: 'Soil Moisture Voltage': Sending state 0.17900 v with 0 decimals of accuracy
In Soil WET
[16:23:07][D][sensor:127]: 'Soil Moisture Voltage': Sending state 0.80100 v with 0 decimals of accuracy
[16:23:08][D][sensor:127]: 'Soil Moisture Voltage': Sending state 0.78200 v with 0 decimals of accuracy
[16:23:09][D][sensor:127]: 'Soil Moisture Voltage': Sending state 0.78800 v with 0 decimals of accuracy
[16:23:10][D][sensor:127]: 'Soil Moisture Voltage': Sending state 0.79400 v with 0 decimals of accuracy
[16:23:11][D][sensor:127]: 'Soil Moisture Voltage': Sending state 0.79000 v with 0 decimals of accuracy
[16:23:12][D][sensor:127]: 'Soil Moisture Voltage': Sending state 0.78800 v with 0 decimals of accuracy
[16:23:13][D][sensor:127]: 'Soil Moisture Voltage': Sending state 0.78800 v with 0 decimals of accuracy
[16:23:14][D][sensor:127]: 'Soil Moisture Voltage': Sending state 0.79300 v with 0 decimals of accuracy
DRY
[16:23:15][D][sensor:127]: 'Soil Moisture Voltage': Sending state 0.14100 v with 0 decimals of accuracy
[16:23:16][D][sensor:127]: 'Soil Moisture Voltage': Sending state 0.15600 v with 0 decimals of accuracy
[16:23:17][D][sensor:127]: 'Soil Moisture Voltage': Sending state 0.66200 v with 0 decimals of accuracy
[16:23:18][D][sensor:127]: 'Soil Moisture Voltage': Sending state 0.67000 v with 0 decimals of accuracy
[16:23:19][D][sensor:127]: 'Soil Moisture Voltage': Sending state 0.22700 v with 0 decimals of accuracy
[16:23:20][D][sensor:127]: 'Soil Moisture Voltage': Sending state 0.16600 v with 0 decimals of accuracy
[16:23:21][D][sensor:127]: 'Soil Moisture Voltage': Sending state 0.10800 v with 0 decimals of accuracy
[16:23:22][D][sensor:127]: 'Soil Moisture Voltage': Sending state 0.11700 v with 0 decimals of accuracy
[16:23:23][D][sensor:127]: 'Soil Moisture Voltage': Sending state 0.14900 v with 0 decimals of accuracy
[16:23:24][D][sensor:127]: 'Soil Moisture Voltage': Sending state 0.15800 v with 0 decimals of accuracy
[16:23:25][D][sensor:127]: 'Soil Moisture Voltage': Sending state 0.18100 v with 0 decimals of accuracy
[16:23:26][D][sensor:127]: 'Soil Moisture Voltage': Sending state 0.07500 v with 0 decimals of accuracy
[16:23:27][D][sensor:127]: 'Soil Moisture Voltage': Sending state 0.07700 v with 0 decimals of accuracy
[16:23:28][D][sensor:127]: 'Soil Moisture Voltage': Sending state 0.13300 v with 0 decimals of accuracy
[16:23:29][D][sensor:127]: 'Soil Moisture Voltage': Sending state 0.16900 v with 0 decimals of accuracy
[16:23:30][D][sensor:127]: 'Soil Moisture Voltage': Sending state 0.18700 v with 0 decimals of accuracy
[16:23:31][D][sensor:127]: 'Soil Moisture Voltage': Sending state 0.08000 v with 0 decimals of accuracy
[16:23:32][D][sensor:127]: 'Soil Moisture Voltage': Sending state 0.07500 v with 0 decimals of accuracy
[16:23:33][D][sensor:127]: 'Soil Moisture Voltage': Sending state 0.11100 v with 0 decimals of accuracy
[16:23:34][D][sensor:127]: 'Soil Moisture Voltage': Sending state 0.14000 v with 0 decimals of accuracy
[16:23:35][D][sensor:127]: 'Soil Moisture Voltage': Sending state 0.17500 v with 0 decimals of accuracy
1 Like

I believe having it always powered like this will totally kill sensor lifetime (electrolysis/corrosion).

I think you might be able to power down / turn off the gpio between readings to help but I’m not sure.

I use one in a deep sleep cycle and it only gets powered during sensor reading.

I will keep trying with the board, hopefully it will work :\ thank you so much for your help @Mahko_Mahko

1 Like

So I was able to figure this out by adding

    attenuation: auto
1 Like

Hello! I’m trying to put two sensors (dht11 and soil moisture) on ESP32 in ESPHOME. However, it gives the following error:
“Duplicate key “platform””

platform: adc
id: moisture01_v
pin: GPIO34
name: "Soil Moisture"
unit_of_measurement: "%"
accuracy_decimals: 0
update_interval: 30s


platform: dht
pin: GPIO03
temperature:
  name: "Temperatura ESP32"
humidity:
  name: "Umidade do Ar ESP32"
update_interval: 30s

What am I doing wrong?
Note: I want to measure in % and not in v, like the friend above.

can you paste the original code,
are you missing the - ?

  • platform: dht as example
  1. You are using ADC incorrectly. It will report Volts at the pin, so you have to use a linear calibration. So you will then need to calibrate it. I assume the sensor will help with its data sheet.
  1. Your code is wrong for both.

remember they both go under one heading

sensor:
> esphome:
  name: sensor-
esp32:
  board: esp32dev
  framework:
    type: arduino
# Enable logging
logger:
# Enable Home Assistant API
api:
  encryption:
    key: "xxxx"
ota:
  password: "xxx"
wifi:
  ssid: "xxxx"
  password: xxx

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Sensor-"
    password: "xxxx"

captive_portal:

platform: adc
id: moisture01_v
pin: GPIO36
name: "Soil Moisture Voltage"
unit_of_measurement: "v"
accuracy_decimals: 0
update_interval: 30s 
    
platform: dht
pin: GPIO03
temperature:
  name: "Temperatura ESP32"
humidity:
  name: "Umidade do Ar ESP32"
update_interval: 30s

Hello @cartman182, your code is wrong/ missing/ indentation. You need to copy and paste in the code from the two examples above and make sure you include

sensor:

Above the ADC line. Same as the example. Repost if you need to

Thanks!
Now my code is running

sensor:
  
- platform: adc
  id: moisture01_v
  pin: GPIO36
  name: "Umidade do Solo"
  update_interval: 5s
  unit_of_measurement: "%"
  attenuation: 11db #(only on ESP32)
  filters:
    - median:
        window_size: 7
        send_every: 4
        send_first_at: 1
    - calibrate_linear:
        - 0.081 -> 100
        - 0.075 -> 0
    - lambda: |
        if (x < 0) return 0; 
        else if (x > 100) return 100;
        else return (x);
  accuracy_decimals: 0

- platform: adc
  pin: GPIO36
  attenuation: auto
  name: "Voltagem do Solo"
  unit_of_measurement: "V"
  device_class: voltage
  update_interval: 5s
  accuracy_decimals: 2
   
- platform: dht
  pin: GPIO03
  temperature:
    name: "Temperatura ESP32"
  humidity:
    name: "Umidade do Ar ESP32"
  update_interval: 30s    

But is not calibrated yet.
What this lambda do? How I find this voltage? My voltage is 0,075 dry and 0,08 wet its correct? My sensor is aways 100%.
How can I put this auto calibration on esphome?
auto calibration program
Instead of finding the value, can’t I get a LOW variable where it is substituted for each value below LOW and a HIGH variable where it is substituted for each value above that value?

where did you find this info? setting this up is driving me crazy…
my values don’t change from 0.14200 regardless of wet/dry

esphome:
  name: esphome-web-x
  friendly_name: Hall ESP32

esp32:
  board: esp32dev
  framework:
    type: Arduino

#sensor: failing
#  - platform: adc
#    id: moisture01_v
#    pin: GPIO36 #GPIO36
#    name: "Soil Moisture Voltage"
#    unit_of_measurement: "v"
#    accuracy_decimals: 0
#    update_interval: 3s

sensor: #consistant - but not right
  - platform: adc
    id: moisture01_v
    pin: GPIO36 #9
    name: "Soil Moisture"
    update_interval: 5s
    unit_of_measurement: "%"
    attenuation: 11db #(only on ESP32)
  #filters:
  #  - median:
   #     window_size: 7
   #     send_every: 4
   #     send_first_at: 1
   # - calibrate_linear:
   #     - 0.14200 -> 100
    #    - 0.075 -> 0
 #   - lambda: |
 #       if (x < 0) return 0; 
 #       else if (x > 100) return 100;
#      else return (x);
    accuracy_decimals: 0

if I enable from filters down I get errors - while parsing a block collection
in “/config/esphome/esphome-web-b03294.yaml”, line 23, column 3
(platform adc line)

expected , but found ‘?’
in “/config/esphome/esphome-web-b03294.yaml”, line 30, column 3
(filters line)

[08:13:01][D][sensor:094]: ‘Soil Moisture’: Sending state 0.14200 % with 0 decimals of accuracy
[08:13:06][D][sensor:094]: ‘Soil Moisture’: Sending state 0.14200 % with 0 decimals of accuracy
[08:13:11][D][sensor:094]: ‘Soil Moisture’: Sending state 0.14200 % with 0 decimals of accuracy
[08:13:16][D][sensor:094]: ‘Soil Moisture’: Sending state 0.14200 % with 0 decimals of accuracy
[08:13:21][D][sensor:094]: ‘Soil Moisture’: Sending state 0.14200 % with 0 decimals of accuracy
[08:13:26][D][sensor:094]: ‘Soil Moisture’: Sending state 0.14200 % with 0 decimals of accuracy
[08:13:31][D][sensor:094]: ‘Soil Moisture’: Sending state 0.14200 % with 0 decimals of accuracy
[08:13:36][D][sensor:094]: ‘Soil Moisture’: Sending state 0.14200 % with 0 decimals of accuracy
[08:13:41][D][sensor:094]: ‘Soil Moisture’: Sending state 0.14200 % with 0 decimals of accuracy
[08:13:46][D][sensor:094]: ‘Soil Moisture’: Sending state 0.14200 % with 0 decimals of accuracy
[08:13:51][D][sensor:094]: ‘Soil Moisture’: Sending state 0.14200 % with 0 decimals of accuracy
[08:13:56][D][sensor:094]: ‘Soil Moisture’: Sending state 0.14200 % with 0 decimals of accuracy
[08:14:01][D][sensor:094]: ‘Soil Moisture’: Sending state 0.14200 % with 0 decimals of accuracy
[08:14:06][D][sensor:094]: ‘Soil Moisture’: Sending state 0.14200 % with 0 decimals of accuracy
[08:14:11][D][sensor:094]: ‘Soil Moisture’: Sending state 0.14200 % with 0 decimals of accuracy
[08:14:16][D][sensor:094]: ‘Soil Moisture’: Sending state 0.14200 % with 0 decimals of accuracy
[08:14:21][D][sensor:094]: ‘Soil Moisture’: Sending state 0.14200 % with 0 decimals of accuracy
[08:14:26][D][sensor:094]: ‘Soil Moisture’: Sending state 0.14200 % with 0 decimals of accuracy
[08:14:31][D][sensor:094]: ‘Soil Moisture’: Sending state 0.14200 % with 0 decimals of accuracy
[08:14:36][D][sensor:094]: ‘Soil Moisture’: Sending state 0.14200 % with 0 decimals of accuracy