DHT11 Library

Hi,

Recently I bought a DHT11 sensor, and using codes from the arduino site and other websites i try to run the sensor, but it always gives me 0 at the values.
I think it can be a problem of how i installed the library

Someone can help me ? Please, I'm really lost

Hi pep-f

Please post your code, so that people can review it.

And post a link to where you downloaded the library.

Sound like the program is running, so it compiled and loaded OK?

Regards

Ray

There's a duplicate folder.
There's two folders named DHT11, one inside the other. You need to move everything from the folder in the lower level to the folder in the higher level and delete the empty folder. You also need to make sure the "Examples" folder is in the folder that you moved everything to.
Take a screenshot of your expanded Windows file tree for that library folder and post it.

// Example testing sketch for various DHT humidity/temperature sensors
// Written by ladyada, public domain

#include "DHT.h"

#define DHTPIN 2     // what pin we're connected to

// Uncomment whatever type you're using!
//#define DHTTYPE DHT11   // DHT 11 
#define DHTTYPE DHT11   // DHT 22  (AM2302)
//#define DHTTYPE DHT21   // DHT 21 (AM2301)

// 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 10K resistor from pin 2 (data) to pin 1 (power) of the sensor

DHT dht(DHTPIN, DHTTYPE);

void setup() {
  Serial.begin(9600); 
  Serial.println("DHTxx test!");
 
  dht.begin();
}

void loop() {
  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  float h = dht.readHumidity();
  float t = dht.readTemperature();

  // check if returns are valid, if they are NaN (not a number) then something went wrong!
  if (isnan(t) || isnan(h)) {
    Serial.println("Failed to read from DHT");
  } else {
    Serial.print("Humidity: "); 
    Serial.print(h);
    Serial.print(" %\t");
    Serial.print("Temperature: "); 
    Serial.print(t);
    Serial.println(" *C");
  }
}

Link:

Thanks, pep-f

Please confirm that the program compiles and uploads OK?

Can you copy and paste the output from serial monitor when you run it.

Serial monitor:

DHTxx test!
Read failFailed to read from DHT
Humidity: 0.00 % Temperature: 0.00 *C
Humidity: 0.00 % Temperature: 0.00 *C
Humidity: 0.00 % Temperature: 0.00 *C
Read failFailed to read from DHT
Humidity: 0.00 % Temperature: 0.00 *C
Humidity: 0.00 % Temperature: 0.00 *C
Humidity: 0.00 % Temperature: 0.00 *C
Read failFailed to read from DHT
Humidity: 0.00 % Temperature: 0.00 *C
Humidity: 0.00 % Temperature: 0.00 *C
Humidity: 0.00 % Temperature: 0.00 *C
Read failFailed to read from DHT
Humidity: 0.00 % Temperature: 0.00 *C
Humidity: 0.00 % Temperature: 0.00 *C
Humidity: 0.00 % Temperature: 0.00 *C
Read failFailed to read from DHT
Humidity: 0.00 % Temperature: 0.00 *C
Humidity: 0.00 % Temperature: 0.00 *C
Humidity: 0.00 % Temperature: 0.00 *C
Read failFailed to read from DHT
Humidity: 0.00 % Temperature: 0.00 *C

I can upload the program but I doesn't work

OK, that's what I got when I ran your code with the downloaded library and no DHT11 attached, since I don't have one :slight_smile:

Which suggests you could have a hardware problem.

Please post a diagram of how you have the sensor connected to the Arduino. You can draw it by hand and post a photo of it, so long as it is clear.

I would try to explain it to you:

the sensor has 3 pins. On one side it has a minus sign there is where i connect the GND, in the middle goes 5V and the other pin goes to the digitalpin 2

Is it this type, which was shown on the website you linked to?


This one has GND on the right, connection for digital pin in the middle and 5V on the left.

If your one is different from this, do you have a link to details about it?

I try it this way, and it still doesn't working. Probably is a library problem but i don't know what.

Or it could be a faulty sensor. Or it could be bad connections from the sensor to the Arduino.

Or it could be that your type of sensor, unlike the one shown in the photo, does NOT have an onboard pullup resistor and needs to have one added, as with the "standalone" DHT11 sensors.

If you can post a close-up photo of your sensor and a link to details about (e.g. the product listing where you bought it), maybe we can help. Also, please post a photo of how you have it connected to the Arduino.

Your original post said ...

using codes from the arduino site and other websites i try to run the sensor, but it always gives me 0 at the values.

If you have tried different libraries and you are still getting the same 0 readings, it does sound like a hardware problem.

have you tried my lib, slightly different - Arduino Playground - DHTLib - ?

confirmed to work on several processors.