下载库文件 http://pan.baidu.com/s/1qWkn4fU,整个文件夹放入 .\arduino-1.5.6-r2\libraries文件夹中
函数解释:
read11(uint8pin) :启动函数,填入DHT11数据口,返回值为0,-1,-2,表示正常,错误,超时
read22(uint8 pin):数据口,DHT22的启动函数,其他与以上一致
temperature:返回温度值
humidity:返回湿度值
测验代码,输出口接在12脚
#include #define DHT11 12//set pin12 as sensor link
dht DHT;
void setup() { // put your setup code here, to run once: Serial.begin(9600); Serial.println("DHT11 data cout:");
}
void loop() { delay(1000);//Wait int check = DHT.read11(DHT11); Serial.print("Current state: "); Serial.print(check); Serial.print(" "); Serial.print("Temperature:"); Serial.print(DHT.temperature); Serial.print(" "); Serial.print("Humidity:"); Serial.println(DHT.humidity,1); }