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