DHT 11 Sensor Problem

Hi,
I was trying to print Temperature and Humidity to an lcdscreen. I connected everything and after I
Uploaded the Sketch my Sensor is only showing nan.
I googled it but I coudn´t find an answer. My sensor was in a Box for a while. Then came the issue.
Is my Sensor damaged?
Or is it just a Programm issue?

Signalpin from DHT11 to Pin D2

Here is my Sketch:

#include “DHT.h” //DHT Bibliothek laden

#include <LiquidCrystal.h>

#define DHTPIN 2 //Der Sensor wird an PIN 2 angeschlossen

#define DHTTYPE DHT11 // Es handelt sich um den DHT11 Sensor

DHT dht(DHTPIN, DHTTYPE); //Der Sensor wird ab jetzt mit „dth“ angesprochen
LiquidCrystal lcd (12, 11, 9, 8, 7, 6);
void setup() {
Serial.begin(9600); //Serielle Verbindung starten
lcd.begin(16, 2);
dht.begin(); //DHT11 Sensor starten

}

void loop() {

delay(5000); //Zwei Sekunden Vorlaufzeit bis zur Messung (der Sensor ist etwas träge)

float Luftfeuchtigkeit = dht.readHumidity(); //die Luftfeuchtigkeit auslesen und unter „Luftfeutchtigkeit“ speichern

float Temperatur = dht.readTemperature();//die Temperatur auslesen und unter „Temperatur“ speichern

lcd.print(Luftfeuchtigkeit); //die Dazugehörigen Werte anzeigen
lcd.setCursor(0, 1);
lcd.print(Temperatur);

Serial.print(“Luftfeuchtigkeit: “); //Im seriellen Monitor den Text und
Serial.print(Luftfeuchtigkeit); //die Dazugehörigen Werte anzeigen
Serial.println(” %”);
Serial.print(“Temperatur: “);
Serial.print(Temperatur);
Serial.println(” Grad Celsius”);

}

Please use code tags (</> button on the toolbar) when you post code or warning/error messages. The reason is that the forum software can interpret parts of your code as markup, leading to confusion, wasted time, and a reduced chance for you to get help with your problem. This will also make it easier to read your code and to copy it to the IDE or editor. If your browser doesn’t show the posting toolbar then you can just manually add the code tags:
[code]``[color=blue]// your code is here[/color]``[/code]
Using code tags and other important information is explained in the How to use this forum post. Please read it.

Post a link to where you got the DHT library from. Please use the chain links icon on the toolbar to make it clickable. Or if you installed it using Library Manger (Sketch > Include Library > Manage Libraries) then say so and state the full name of the library.

is your display showing :

Luftfeuchtigkeit: nan % Temperatur: nan Grad Celsius

also, how many characters does your display work with ?

it seems like there are a lot of characters for a display, maybe try

  Serial.print("RH: "); //Im seriellen Monitor den Text und 
  Serial.print(Luftfeuchtigkeit); //die Dazugehörigen Werte anzeigen
  Serial.println(" %");
  Serial.print("T : ");
  Serial.print(Temperatur);
  Serial.println(" Grad C");

yes it shows

Serial Monitor:

Luftfeuchtigkeit: nan % Temperatur: nan Grad Celsius

Display: nan nannan

This is the Link where I got DHT.h

https://github.com/adafruit/DHT-sensor-library

And I also installed the DHT sensor libary from Adafruit (Version 1.3.0)

the library seems to test for a connection, if not connected, it results in nan

https://github.com/adafruit/DHT-sensor-library/blob/master/DHT.cpp

line 72

float DHT::readHumidity(bool force) {
      float f = NAN;
      if (read()) {
        switch (_type) {
        case DHT11:
          f = data[0];
          break;
        case DHT22:
        case DHT21:
          f = data[0];
          f *= 256;
          f += data[1];
          f *= 0.1;
          break;
        }
      }
      return f;

check your wiring. check voltage at the sensor. maybe try a different pin

I checked the Voltage with a Voltmeter it is at 4.6-4.8 I also tried a different pin and changed the Cable 2 times. But it still does not work.

Did you use a pull-up resistor on the data pin? How long is your cable?

I dont use a pull-up resistor. My cable is 20cm long.

PaulRB: Did you use a pull-up resistor on the data pin? How long is your cable?

Try, add 4.7k to 10k, see what happens

Also, there are two example sketches in GitHub. One has the reporting to notify that the unit is not found. you might want to use the example sketch and see what happens.

the other example requires a second library be in the sketch.

I tried it with an 5k resistor and a 10k. Still not working.

The Orange Wire goes to Pin 2

that board may have a 10k pull up on it. look at the bottom of the PCB near the signal pin.

picture from your post

there are two packages with the device on the board.

one has a mounting hole between the pins and the blue enclosure.
this has signal on the middle pin.

then there is the Keyes version with the pins very close to the enclosure and there is a resistor on the board.
signal is marked with an S and is on the left.

Yes it has an 10k Pull up resistor.

I have a raw DHT11, not on a board, it has 4 pins.

I used the internal pull-up for pin 2

I remarked out all the LCD stuff.

Since your code worked for me after I remarked out the LCD bits, I suggest you try it and see if it works for you.

#include "DHT.h" //DHT Bibliothek laden

//#include <LiquidCrystal.h>

#define DHTPIN 2//Der Sensor wird an PIN 2 angeschlossen   
#define DHTTYPE DHT11    // Es handelt sich um den DHT11 Sensor
DHT dht(DHTPIN, DHTTYPE); //Der Sensor wird ab jetzt mit „dth" angesprochen
//LiquidCrystal lcd (12, 11, 9, 8, 7, 6);

void setup() {
  Serial.begin(9600); //Serielle Verbindung starten
 // lcd.begin(16, 2);
  pinMode(2, INPUT_PULLUP); 
  dht.begin(); //DHT11 Sensor starten
 
}
void loop() {
  delay(5000); //Zwei Sekunden Vorlaufzeit bis zur Messung (der Sensor ist etwas träge)
  float Luftfeuchtigkeit = dht.readHumidity(); //die Luftfeuchtigkeit auslesen und unter „Luftfeutchtigkeit" speichern
  float Temperatur = dht.readTemperature();//die Temperatur auslesen und unter „Temperatur" speichern
  //lcd.print(Luftfeuchtigkeit); //die Dazugehörigen Werte anzeigen
  //lcd.setCursor(0, 1);
  //lcd.print(Temperatur);
  Serial.print("Luftfeuchtigkeit: "); //Im seriellen Monitor den Text und
  Serial.print(Luftfeuchtigkeit); //die Dazugehörigen Werte anzeigen
  Serial.println(" %");
  Serial.print("Temperatur: ");
  Serial.print(Temperatur);
  Serial.println(" Grad Celsius");
}