I was using the DHT11 sensor when I ran into a problem it runs great the code was uploaded and when I ran it I got the output both for temp and humidity "NaN". The code that I was using is this :
NaN is almost always the result of a divide by zero. Since you aren't dividing that's probably something in the DHT.h library and I have no clue what it's doing...
I am having the same problem: I tried multiple sketches and libraries and even (3 pin) DHT11 sensors, but whatever I try, I get no output. It is either zero or nan.
Forgive me. I am a new user of this forum and I am not familiar to all rules.
But why should I start a new topic? The initiator of this topic and I have the exact same problem. Would it not be simple to keep all answers in one topic?
The reason to start a new thread is because you and the OP may have the same symptom but potentially not at all the "exact same problem" but rather different problems, different sensors, different boards you are trying to use, different code etc.
The OP who never responded again to any suggestions posted code which does not even work because instead of performing Serial.begin(9600); he coded it Serial.print(9600); so his code as posted never printed anything Nan or otherwise to the Serial monitor.
I tried to reproduce this error with several different libraries, including Adafruit, DFRobot, a couple of others. The only time I got a Nan error was when I intentionally wired the sensor incorrectly. The 4 pin version is the actual sensor, it should be standard pin out. 3 pin versions are the same 4 pin sensor on a breakout board with a pullup resistor already in place. A web search reveals they have pinouts that vary from manufacturer to manufacturer.
I suggest if you get the sensor you have wired correctly (which we don't know anything about, hence one of various reasons to start your own thread) any of the common libraries will work fine.
Just one more post from me to close this subject. I tried the solutions provided by v205 and xfpd, but I just could not get it working.
Searching the internet I learned there are many people struggeling with these sensors. That is why I decided to try an other sensor: the Adafruit AHT20. That sensor really works great.
So: my advice for topic starter and all people who want a temperature and humidity sensor. Do not use DHT11, but use AHT instead.