0

I am trying to use DHT11 sensor with Arduino. But unfortunately it is returning following values:

Temperature = 1.00 Humidity = 2.00

My code is as follows:

#include <dht.h>
dht DHT;
#define DHT11_PIN 7

void setup(){
   Serial.begin(9600);
}

void loop()
{
    int chk = DHT.read11(DHT11_PIN);
    Serial.print("Temperature = ");
    Serial.println(DHT.temperature);
    Serial.print("Humidity = ");
    Serial.println(DHT.humidity);
    delay(1000);
}

Link to the library I am using is here

I have connected +ve to 3.3 V I have connected -ve to Ground I have connected out to digital pin # 7

enter image description here enter image description here enter image description here

  • Current temperature of the room otherwise is 34 degree celsius and 62% Humidity – Saad Bashir Aug 19 '17 at 11:18
3

You have to call the functions:

#include <DHT.h>
#define DHT11_PIN 7
DHT dht(DHT11_PIN, DHT11);

void setup() {
    Serial.begin(9600);
    dht.begin();
}

void loop() {

    float humidity = dht.readHumidity();
    float temperature = dht.readTemperature();

   if (isnan(humidity) || isnan(temperature)) {
      Serial.println("Failed to read from DHT sensor!");
      return;
    }

    Serial.print("Temperature = ");
    Serial.println(temperature);
    Serial.print("Humidity = ");
    Serial.println(humidity);

    delay(1000);
}

Edit

enter image description here

  • It seems that you are using a different library. Can you tell me which library are you using for this code? – Saad Bashir Aug 19 '17 at 11:34
  • I'm using the Adafruit DHT library, here github.com/adafruit/DHT-sensor-library. I've been using it for more than a year; no complains. – user31481 Aug 19 '17 at 11:36
  • Serial.begin(9600); was missing so I added that in your code and I still get the same output as before. Temperature 1 and Humidity 2 – Saad Bashir Aug 19 '17 at 11:45
  • @Saad. I tested the same sketch on my lab. It works, but sometimes the DHT act funny. Check connections, place a 4.7K resistor between Vcc and Data Line. – user31481 Aug 19 '17 at 13:49
  • Ahmm I am not quite good with circuits. So not sure if I am supposed to put one at both places or just use one resistor. And secondly I only have 10k resistors at the moment :O would they work? – Saad Bashir Aug 19 '17 at 14:03
2

This is not a DHT11, DHT11 is blue, DHT21 is black, and DHT 22 is white. It must be a DHT22 hence the wrong values.

EDIT : on your pictures the white case says AM2302, it's definitely a DHT22 the code must be adapted accordingly.

  • I had the reverse problem: I used a DHT11 (blue one) instead of a dht22 (white one). The value I got were in the 500`C for the temperature and the 1500% for humidity. Replacing the DHT11 by the DHT22 solve it. – MagTun Dec 2 '18 at 5:57

Not the answer you're looking for? Browse other questions tagged or ask your own question.