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
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");
}
}
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
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.