#include <DHT.h>
#include <DHT_U.h>
#define DHTPIN 12 //digital pin connected to the DHT sensor
#define DHTTYPE DHT22 //DHT11
DHT dht(DHTPIN, DHTTYPE);
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial.println("DHT22 test!");
dht.begin();
}
void loop() {
// put your main code here, to run repeatedly:
delay(2000);
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t))
{
Serial.println("Failed to read from the DHT sensor!");
return ;
}
Serial.print("Humidity:");
Serial.print(h);
Serial.print("\t");
Serial.print("Temperature: ");
Serial.print(t);
Serial.print("*c");
}