-->
Page 1 of 1

ESP8266 can't read Temperature & Humidity from DHT21/AM2301

PostPosted: Fri Sep 04, 2015 10:22 pm
by Nguyen
I followed the instruction: https://github.com/adafruit/DHT-sensor-library and upload DHTtest.ino to Esp8266

Connect pin 1 (on the left) of the sensor to +5V
Connect pin 2 of the sensor to whatever your DHTPIN is
Connect pin 4 (on the right) of the sensor to GROUND
Connect a 1K resistor from pin 2 (data) to pin 1 (power) of the sensor

but after done uploading, Serial Monitor print: "Failed to read from DHT sensor!"
I don't know what reason and how to fix
Thanks!

Re: ESP8266 can't read Temperature & Humidity from DHT21/AM2

PostPosted: Sun Sep 06, 2015 3:07 pm
by AcmeUK
I had that problem, the Adafruit script, as is, does not work with the DHT21. There is an updated script that worked for me, however I am away from home and do not have access to it. I think it involved instancing the DHT is a third parameter.

I have looked but cannot locate the file. In the Adafruit DHT-sensor-lib on github the example code contains this statement:-
// Initialize DHT sensor.
// Note that older versions of this library took an optional third parameter to
// tweak the timings for faster processors. This parameter is no longer needed
// as the current DHT reading algorithm adjusts itself to work on faster procs.

If I remember correctly I used this to instance the DHT :-
DHT dht(DHTPIN, DHTTYPE, 30);

Also ensure that you have the DHT defined as the device in use.

Hope this has helped. Good Luck

Re: ESP8266 can't read Temperature & Humidity from DHT21/AM2

PostPosted: Tue Sep 08, 2015 1:03 pm
by Nguyen
AcmeUK wrote:I had that problem, the Adafruit script, as is, does not work with the DHT21. There is an updated script that worked for me, however I am away from home and do not have access to it. I think it involved instancing the DHT is a third parameter.

I have looked but cannot locate the file. In the Adafruit DHT-sensor-lib on github the example code contains this statement:-
// Initialize DHT sensor.
// Note that older versions of this library took an optional third parameter to
// tweak the timings for faster processors. This parameter is no longer needed
// as the current DHT reading algorithm adjusts itself to work on faster procs.

If I remember correctly I used this to instance the DHT :-
DHT dht(DHTPIN, DHTTYPE, 30);

Also ensure that you have the DHT defined as the device in use.

Hope this has helped. Good Luck


Thank you so much, AcmeUK!
I tried and the problem has been resolved. But I use "DHT dht(DHTPIN, DHTTYPE, 15);"