#include <dht11.h>
dht11 DHT11;
#define DHT11PIN 4
void setup()
{
Serial.begin(9600);
}
void loop()
{
int chk = DHT11.read(DHT11PIN);
Serial.print("Read sensor: ");
switch (chk) //檢驗是否正常運行
{
case 0: Serial.println("OK"); break;
case -1: Serial.println("Checksum error"); break;
case -2: Serial.println("Time out error"); break;
default: Serial.println("Unknown error"); break;
}
Serial.print("Humidity (%): "); //濕度
Serial.println((float)DHT11.humidity, 2);
Serial.print("Temperature (oC): "); //溫度
Serial.println((float)DHT11.temperature, 2);
delay(2000);
}