DHT11 sensor returns value nan only
#define DHTPIN D4
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
float h = dht.readHumidity();
float t = dht.readTemperature();
Serial.print((String)"Temperature = " + t + " °C");
Serial.print((String)"Humidity = " + h + " %");
Welcome to the forum.
Thanks for using code tags in your post.
I believe "nan" mans that the code has timed out trying to communicate with the DHT11 sensor.
There are many libraries around called DHT, can you tell us where you downloaded the library you are using.
Can you please post a circuit diagram?
Have you got the 4K7 resistor from the DTH11 signal pin to 5V?
You could try
#define DHTPIN 4
Hello, thanks for the reply
I used the DHT sensor library by Adafruit - Ver 1.4.2
I am interfacing my 3 pin DHT11 with NodeMCU and a power supply module that I've connected to with a 9V battery
Unfortunately I dont have Fritzing so I cant post a circuit diagram
Thats fine, Fritzy is not a very good way of presenting a schematic.
A picture of a hand drawn circuit will be fine.
Have you got a DMM?
PS. Good night I'm off to bed..
Have you tried using this example code?
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.
i've got the same NaN error with DHT11 once it did work well some time ago. Adding an external power supply solved the NaN problem to me.
Hope it helps,