Esphome.io + NodeMCU and DHT22 or AM312 nothing working

I recently used esphome.io to create a washing machine and dryer monitoring system and it worked very well. So well, I thought I’m going to build a bunch of stuff! I ordered temp/humidity sensors, motion sensors, distance sensors, some relays and some other stuff to play around building things. Anyway, I started to get some of the components and for a quick and easy test I decided to wire up the PIR AM312 and the DHT22/AM2302 to my NodeMCU and program it with EspHome quickly to watch it work.

To my amazement, I’ve spent half the day trying to get it to work and it’s still just spitting out messages like this:

[20:26:26][W][dht:120]: Requesting data from DHT failed!
[20:26:26][W][dht:058]: Invalid readings! Please check your wiring (pull-up resistor, pin number).
[20:26:56][W][dht:120]: Requesting data from DHT failed!
[20:26:56][W][dht:058]: Invalid readings! Please check your wiring (pull-up resistor, pin number).
[20:27:26][W][dht:120]: Requesting data from DHT failed!
[20:27:26][W][dht:058]: Invalid readings! Please check your wiring (pull-up resistor, pin number).
[20:27:56][W][dht:120]: Requesting data from DHT failed!
[20:27:56][W][dht:058]: Invalid readings! Please check your wiring (pull-up resistor, pin number).
[20:28:01][I][ota:046]: Boot seems successful, resetting boot loop counter.
[20:28:26][W][dht:120]: Requesting data from DHT failed!
[20:28:26][W][dht:058]: Invalid readings! Please check your wiring (pull-up resistor, pin number).
[20:28:56][W][dht:120]: Requesting data from DHT failed!

My esphome config file currently looks like this:

esphome:
  name: testing
  platform: ESP8266
  board: nodemcuv2

wifi:
  ssid: "MySSID"
  password: "MyPW"
  domain: "MyNet"

logger:
  level: DEBUG

api:
  password: 'testing'

ota:
  password: 'testing'

sensor:
  - platform: dht
    pin: D1
    model: AM2302
    temperature:
      name: "Office Temperature"
    humidity:
      name: "Office Humidity"
    update_interval: 30s 

binary_sensor:
  - platform: gpio
    pin: D2
    device_class: motion
    name: "Office Motion"

For the temperature/humidity sensor, I tried moving the input pins around, I tried using the DHT22 model instead of the AM2302. I tried powering the sensor from the 5V line instead of the 3V line. It seems to always say those two messages, every thirty seconds.

For the PIR motion sensor (AM312), if I comment out the temperature/humidity sensor when I upload the config and the NodeMCU reboots, absolutely nothing comes out. It’s like I programmed an empty config file to the thing or something.

I’m not sure why neither of these are working, can someone please let me know where I’m going wrong?

The DHT22 sensor I’m using looks exactly like this one:

Here’s a picture of one of my AM312 sensors:


As you can see, there are no clear markings of which pin is which, so maybe I’m hooking it up wrong?

I’ve made some ESPHome sensors with those components. My PIR looks just like yours, and the pinout is

pin next to U1 = +5V
middle pin = signal
pin next to C1 = ground

Your DHT pins seem clearly marked. (The pins on my DHT sensor (different manufacturer) are marked as, from left to right, + out -). The ESPHome documentation states

“The DHT22 and DHT11 require external pull up resistors on the data line. To do this, solder a resistor with about 4.7kΩ (anything in the range from 1kΩ to 10kΩ probably works fine, but if you’re having issues try the 4.7kΩ recommended by the manufacturer) between DATA and 3.3V .”

I didn’t put the resistor in initially, and I got those same errors. When I added the resistor, they went away.

The relevant part of my code is

sensor:
  - platform: dht
    model: AM2302
    pin: D7
    temperature:
      name: "Sensor Temperature"
    humidity:
      name: "Sensor Humidity"
    
binary_sensor:
  - platform: gpio
    pin: D5
    name: "Sensor Motion"
    device_class: motion

which looks just like yours, except for the update interval.

Hope something in that helps you!

Hi Anwen, thanks for the comments.

I did see that note about the resistors on the ESPHome website. Does your DHT sensor look like mine with the PCB? Mine has a surface mount resistor built in. I measured it with my DMM and it comes in at 3.2kΩ. Maybe that’s not enough? I guess I’ll try adding another small resistor in series to bump it up a bit more and see if that does the trick.

On the PIR sensor, do you get any messages out with the DEBUG when looking at the device through the ESPHome interface or is it completely silent? After I upload the firmware and it seems to be running, I don’t see any new devices in home assistant and I don’t get any errors nor debug messages if I only compile in the PIR which seems weird.

You use the VV pin for the +5V? Do you route this to both the PIR and the DHT for power? I found a video by The Hook Up for picking the best input and output pins on NodeMCU (https://www.youtube.com/watch?v=7h2bE2vNoaY) so I moved to D1 and D2 for these sensors but was still unable to get them to do what I want. Maybe, I’ll try your exact file and configure the pins that way and see if I have any luck.

Thanks again!
-Greg

My DHT looks like this one

dht22

My PIR shows up in HA as a binary sensor, and I do see motion on and motion off events when I watch the ESPHome log. It’s connected to Vin on the NodeMCU. The DHT is connected to 3V3.

Maybe your PIR unit is bad. Do you have another one to try?

Anwen, I tried adding a couple of 560Ω in series between the output and VCC and that did the trick! Thanks for the help.
-Greg

1 Like

Glad you got it working!

FWIW I had the same issue - basically getting “Requesting data from DHT failed” errors. Interesting thing is I had been using exactly the same kit to upload data to thingiverse so I knew that it should work. I changed the wiring so the AM2302 was being fed by 3V rather than 5V from my D1 mini, and yay - instantly started working. So the learning here is that esphome is a little more sensitive to errors so if you feed the AM2302/DHT22 5V then (if you are using one mounted on a board) you will probably need to add extra pull up resistance to that provided on the board itself. Just to be safe, I might add on a resistor anyhow. :wink:

1 Like

i had trouble with getting signal from my AM312 when making bruh sensor.
it should work with 2,7v but i had to give it EXTERNAL5V to make it work.
(did not get signal when AM312 was powered from Node mcu VIN or 3V)
So im powering my Node MCU,s with 5V to VIN,
(check your board, but think a few of them can be powered with up to 20V)
my got hot when running from 12V so i used 12V powersupply, and a small buck converter to 5V connected to VIN. Works like a charm now.
EDIT on my AM312 the small dot besides one outer pin (see your picture) is power pin. (on mine at least) Center is usually signal. so last one would be ground.

Aideepen ESP8266 ESP-01 AM2302 DHT22 Temperature Humidity Sensor WiFi Wireless Module for Arduino Replace SHT11 SHT15

can anyone help with this using home assistant just cant get it working

esphome:
name: temp6
platform: ESP8266
board: esp01_1m

wifi:
ssid: “xxxxxx”
password: “xxxxxxx”

Enable fallback hotspot (captive portal) in case wifi connection fails

ap:
ssid: “Temp6 Fallback Hotspot”
password: “xxxxxxx”

captive_portal:

Enable logging

logger:

Enable Home Assistant API

api:

ota:

sensor:

  • platform: dht
    model: AM2302
    pin: 1
    temperature:
    name: “Sensor Temperature”
    humidity:
    name: “Sensor Humidity”

Hi! I have also weird behaviour with DHT sensors, PIR and ESP32s or ESP8266s.
DHT sensor is AM2320 and the PIR is HC-SR501.
When the ESP boots AND if the PIR sensor is connected then 9/10 times the ESPHome cannot find the DHT sensor.
If I unplug the PIR, boot the ESP and wait couple seconds until plugging the PIR back, then everything works.
I have added pull-up resistors to I2C data lines, but this behaviour persists.

I have one ESP32 with PIR and BME280 and it does not have any problems. Seems to be related to combination of DHT and PIR.

Anyone have similar observations?

I have…let me count…six nodemcu’s with dht22’ and 501 PIR’s on the same board crammed in the same box. No issues at all. One issue I had was with a couple of the most recent dht22’s I ended up with: they are the kind mointed to the large red board. I had to define them as a DHT_TYPE2 in my esphome config file. This is not available on the stable release yet, only beta I think.

Hi,
I recently plugged and DHT22 (AM2302) and PIN 2 of my ESP32.
My code is really simple and seems working :

esphome:
  name: compteurs
  platform: ESP32
  board: nodemcu-32s

wifi:
  ssid: ***
  password: ***

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: ***
    password: ***

captive_portal:

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:

sensor:
  - platform: dht
    pin: 2
    temperature:
      name: "Température Cave"
      filters:
        - offset: 29.0
    humidity:
      name: "Humidité Cave"
      filters:
        - offset: 40.0
    update_interval: 60s

As you can see, I need to put offsets filters to have “corrects” values.

Because I don’t have, I didn’t put any resistors like it’s recommended there : https://esphome.io/components/sensor/dht.html
Could it the reason why I get periodical values like we can see on my graphs and I need to put offsets :
Capture1
Capture2

The resistor is required because the DHT data pin needs to be held high, and then pulled low by the MCU to start communication. The DHT then responds by pulling the pin low pin a pulse train to transmit data. Without the resistor, it might work somewhat due to the natural tendency of the line to end up high because of stray capacitance, leakage, etc. However it wont be reliable.

DHT22_TYPE2 worked for me, ty

3 Likes

ok. for me work:

sensor:
  - platform: dht
    pin: D0
    model: DHT11
    temperature:
      name: "Example Temperature"
    humidity:
      name: "Example Humidity"
    update_interval: 10s

Not sure if someone got same issue as mine. I know, you had set up another GPIO pin, but my case was with same error, but different solution. I was using pin 34, and didn’t know DHT22 has to be connected to IN&OUT pin (needs bidirectional communication), so changed from 34 to 4 and started working fine (also with a PIR working). While programming, appeared a warning, for avoid to use pin 4, so after it working in pin4, changed again pin to 23. It works fine now.
Cheers.

This also worked for me