Post topics, source code that relate to the Arduino Platform

User avatar
By Nguyen
#27849 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!
User avatar
By AcmeUK
#27959 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
User avatar
By Nguyen
#28633
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);"