DHT11Default.ino (877B)
1 #include <SimpleDHT.h> 2 3 // for DHT11, 4 // VCC: 5V or 3V 5 // GND: GND 6 // DATA: 2 7 int pinDHT11 = 2; 8 SimpleDHT11 dht11(pinDHT11); 9 10 void setup() { 11 Serial.begin(115200); 12 } 13 14 void loop() { 15 // start working... 16 Serial.println("================================="); 17 Serial.println("Sample DHT11..."); 18 19 // read without samples. 20 byte temperature = 0; 21 byte humidity = 0; 22 int err = SimpleDHTErrSuccess; 23 if ((err = dht11.read(&temperature, &humidity, NULL)) != SimpleDHTErrSuccess) { 24 Serial.print("Read DHT11 failed, err="); Serial.print(SimpleDHTErrCode(err)); 25 Serial.print(","); Serial.println(SimpleDHTErrDuration(err)); delay(1000); 26 return; 27 } 28 29 Serial.print("Sample OK: "); 30 Serial.print((int)temperature); Serial.print(" *C, "); 31 Serial.print((int)humidity); Serial.println(" H"); 32 33 // DHT11 sampling rate is 1HZ. 34 delay(1500); 35 }