I opened the .cpp file to see what it does and I found these lines:
switch (_type) {
case DHT11:
f = data[0];
return f;
case DHT22:
case DHT21:
f = data[0];
f *= 256;
f += data[1];
f /= 10;
return f;
}
Serial.print("Read fail");
return NAN;
And something similar for temperature. It always prints "Read fail". But I don't know if it is because the library or not. I am using the correct pin and my sketch just is the example they provide. So I think it should work. Do you know another library for testing?
I found a library for dht11 and it worked! Clink the link read the text it will tell you to download a DHT library. Click on the link and save file. Open file and extract the contents. Then on Arduino IDE add the library, be careful cos the file you want to add is inside the file you save the contents to? The scroll down the web page and it gives you a link to some code.
Basically instal the library from the link to Arduino IDE, copy and paste this code and upload.
#include <dht.h>
#define dht_dpin A0 //no ; here. Set equal to channel sensor is on
dht DHT;
void setup(){
Serial.begin(9600);
delay(300);//Let system settle
Serial.println("Humidity and temperature\n\n");
delay(700);//Wait rest of 1000ms recommended delay before
//accessing sensor
}//end "setup()"
void loop(){
//This is the "heart" of the program.
DHT.read11(dht_dpin);
Serial.print("Current humidity = ");
Serial.print(DHT.humidity);
Serial.print("% ");
Serial.print("temperature = ");
Serial.print(DHT.temperature);
Serial.println("C ");
delay(800);//Don't try to access too frequently... in theory
//should be once per two seconds, fastest,
//but seems to work after 0.8 second.
}// end loop()
I found a library for dht11 and it worked! Clink the link read the text it will tell you to download a DHT library. Click on the link and save file. Open file and extract the contents. Then on Arduino IDE add the library, be careful cos the file you want to add is inside the file you save the contents to? The scroll down the web page and it gives you a link to some code.