DHT22 doesn't work on ESP32: cable length vs signal voltage vs "pcb module or bare element" vs resistor usage

Morning everyone,
I’ve got a bit of weird situation with my newest DHT22 here, and before I buy another one I’d like to rule out a few things. It’s my 3rd project with a DHT22, the other 2 work like a charm.

Situation: I’ve got an ESP32 devkit V1 running as my hallway weather display for a while now, originally just with an epaper display and some pushbuttons. Over the weekend I extended the setup with a WS2812 notification LED, a MH-Z19C co2 sensor, and a DHT22 for temperature and humidity. The LED and the MH-Z19C worked out of the box, the DHT22 throws this error:

[07:45:27][W][dht:169]: Requesting data from DHT failed!
[07:45:27][W][dht:060]: Invalid readings! Please check your wiring (pull-up resistor, pin number).

The DHT22 is powered by the 5V from Vin, I’m using the “input only” GPIO 34 of the ESP32.

My (relevant) YAML code for the integration:

sensor:
  - platform: homeassistant
    id: outside_temperature
    entity_id: sensor.lumi_lumi_weather_a5f3bb07_temperature
    internal: true
  - platform: homeassistant
    id: windspeed
    entity_id: sensor.openweathermap_wind_speed
    internal: true
  - platform: homeassistant
    id: maxtemp
    entity_id: sensor.openweathermap_forecast_temperature_2
    internal: true
  - platform: homeassistant
    id: mintemp
    entity_id: sensor.openweathermap_forecast_temperature_low_2
    internal: true
  - platform: dht
    pin: 34
    model: DHT22
    temperature:
      name: "Hallway Temperature"
    humidity:
      name: "Hallway Humidity"
    update_interval: 60s
  - platform: mhz19
    co2:
      name: "hallway co2"
    temperature:
      name: "MH-Z19 Temperature"
    update_interval: 60s
    automatic_baseline_calibration: false

And in case it plays a role, the UART config for the co2 sensor:

uart:
  rx_pin: 35
  tx_pin: 13
  baud_rate: 9600

I’ve been digging through google and this forum, and the usual error cases don’t get me closer to a solution here:

  • add a pullup resistor: I’m already using a “pcb version” of the DHT, which has both a resistor and a capacitor on the board (my other 2 projects use the bare version without resistor though)
  • trying out different types in the setup code: I tried DHT22, DHT22_TYP2 and AM2302
  • signal voltage: I’m powering the DHT via the 5V from the Vin pin of the ESP32, some sources say that I need a level shifter to convert to 3,3 for the signal pin. But: I’ve got a DHT22 running flawlessly with 5V in and out on a ESP8266 for months now
  • cable length: from DHT to pin34 on the board it’s rougly 20-30cm of cable. I have the same length with the 8266 project, no issue there
  • electrical interference: I ran my “mobile” air quality meter (which also uses a DHT22) at the same place in the apartment for hours, no issues there
  • power cut after OTA: I tried dis- and reconnecting the ESP after flashing, not change

Any idea what else I could try out before buying the next DHT22? I’m now wondering if the PCB version of the module is that much different from the “bare” version maybe?

This is the type of module I used:
31Wd1CXIILL.SX342

And this is how it’s set up:

(The upper connectors go to the MH-Z19C. And although there is metal in the picture: the PCB for both sensors is mounted on a plastic bracket, not contact to the metal)

My best bet is that it’s just broken, and I’ll have to get a new one, but maybe I still missed something else…

Cheers!

by the looks of it yes, as you already ruled out most of the “typical” scenarios you could fix (for example by software).

Beside I wouldn’t buy any DHT22 in 2022 (or even back in the year 2020) but go with a sensor that features i2c (like a htu21d for example) one thing you could still try is to solder directly onto the pins of the DHT22 sensor (on the back of the break out board) and add the pull-up resistor to see if you can receive any data.

1 Like

Okay, I think I found it. The DHT22 needs a bidirectional pin, so an “input only” pin like the 34 I used won’t work.

I’ll resolder the data line and will get back afterwards. Will hopefully do the trick.

1 Like

Okay, moved it from 34 to 4, works like a charm.

1 Like