DHT22 fail readings

Hello all,

I’ve setup a WemosD1 mini with a DHT22.
It works perfectly when I switch it on but after half a day or a day it starts failing to read the sensor data, If it reset it from the interface it doesn’t read the data either but if I unplug and plug it again it works (Although I cannot do that every time because It’s placed on a wires box).

I’ve got the 4,7k resistor connected from 3.3v to the data pin.
From the D1 mini to the sensor I have 3 wires with a length of around 30 cm.

  • I’ve tried different pins on the WemosD1
  • I’ve tried with a different sensor
  • I’ve tried powering the DHT22 with 3.3v and 5v from the WemosD1
  • I’ve changed the model: DHT22 to all models available in the documentation

I don’t know what else to try, here is my code.
Any suggestion will be much appreciated.

substitutions:
  device_name: calefaccion
  friendly_name: Calefacción

esphome:
  name: "${device_name}"

esp8266:
  board: d1_mini

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "hiden"

ota:
  - platform: esphome
    password: "hiden"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  manual_ip:
    static_ip: 192.168.1.133
    gateway: 192.168.1.1
    subnet: 255.255.255.0

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "${friendly_name} Fallback Hotspot"
    password: "hiden"

captive_portal:

web_server:
  port: 80

switch:
  - platform: restart
    name: "${friendly_name} Restart"
  - platform: gpio
    name: "${friendly_name}"
    pin: D1

sensor:
  - platform: dht
    pin: 
      number: D5
    temperature:
      name: "Comedor Temperatura"
      accuracy_decimals: 1
    humidity:
      name: "Comedor Humedad"
      accuracy_decimals: 1
    update_interval: 10s
    model: DHT22
    

This is the error message:

[10:21:47][W][dht:174]: Requesting data from DHT failed!
[10:21:47][W][dht:060]: Invalid readings! Please check your wiring (pull-up resistor, pin number).
[10:21:47][D][sensor:093]: 'Comedor Temperatura': Sending state nan °C with 1 decimals of accuracy
[10:21:47][D][sensor:093]: 'Comedor Humedad': Sending state nan % with 1 decimals of accuracy

So if you pull the power and restore it, does it all start working ok again?
If so then try another DHT22 or even a BME sensor as they are apparently the DHT’s are not good quality.

1 Like

Yes, If I unplug the device and plug it, it starts to work again providing temp and humidity for a day or so.
I’ve already tried to use different DHT22 that I have at home but they behave the same.

Don’t do trials like that. You power it from 3.3V and you pull up the data line to 3.3V.
Is your DHT bare sensor or module?
If module, try without external pullup.
If bare sensor, try with 1K or 2K pullup.
A capacitor valued 100nF between VCC and GND can help as well.

1 Like

I tried with 5v because with 3.3v was having issue with the readings and thought that maybe the sensor wasn’t receiving enough power.
It’s is bare sensor and I have a 4.7k resistor from 3.3v to data pin, as the documentation is suggesting. I’ll try with lower resistors values and with the capacitor.
I still don’t understand why is working perfectly and providing accurate measurements and suddenly it stops.

Depends on documentation, Adafruit presents 1K on the datasheet.
Try those fixes. The sensor is quite crap, the only reason I would pick DHT for my setup would be long wiring. In any other case I would pick Sensirion SHT3x or 4x sensor.

2 Likes

Whta I did is I get it to do a restart everyday well twice a day

time:
  - platform: homeassistant
    on_time:
      - seconds: 0
        minutes: 0
        hours: 4
        days_of_week: MON-SUN
        then:
           - switch.toggle: restartit
      - seconds: 0
        minutes: 0
        hours: 16
        days_of_week: MON-SUN
        then:
           - switch.toggle: restartit
switch:
  - platform: restart
    name: "Restart"
    id: restartit

Whta I did is I get it to do a restart everyday well twice a day

I also have the restart switch in the code, although if I restart the module with that switch it doesn’t work. It has to be a hard restart, unplug it from the power and plug it again.

I’ve done the changes by @Karosm to set a 1k resistor and move back the power from 5v to the 3.3v pin and now it’s been working for more than a day with accurate readings.
Also I’ve wrapped the cables from the sensor to the D1 mini with foil as it is in a distribution box and my guess is that the main power cables can affect the signal (It’s a total assumption).

I can’t say is a win since sometimes it fails after a day and a half but it looks promising.
I’ll let you know.

Thanks :smiley:

That can be dangerous in mains distribution box… You could use just some shielded usb/network cable. Also, the shield should be connected to GND on the Esp side.

I’ve wrapped the foil with insulation tube also, so nothing metallic is exposed.
Thanks for the advise, if you think the shrink tube is not enough let me know and I’ll change it straight away.
Thanks again.

I can’t estimate shrink tubes insulation capacity :wink:
Ideally sensor wires don’t travel parallel to power lines.
To give little better protection from interferences, wires are twisted pairs (signal twisted with gnd. If shielded, also shield connected to gnd on supply side.

1 Like

For who it might be interested.
With my last setup with a 1k resistor is more stable, although the DHT22 also gets disconnected and the status of the readings in HA is Unknown.

I wanted to use it as a temperature for my thermostat but is not reliable, I bought some sonoff thermometers instead.