#include <DHT.h>
#define DHT_PIN 2
#define DHT_TYPE DHT22
DHT dht(DHT_PIN, DHT_TYPE);
char buf [80];
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(1000);
float h = dht.readHumidity();
float t = dht.readTemperature();
float f = dht.readTemperature(true);
float hic = dht.computeHeatIndex(t, h, false);
float hif = dht.computeHeatIndex(t, h);
if(isnan(h) || isnan(t) || isnan(f)){
Serial.println(F("Failed to read sensor DHT!"));
return;
}else{
/** sprintf(buf, "Humadity: %d Temperature: %d Heat: %d", h, t, f); **/
Serial.print("Humadity:");
Serial.print(h);
Serial.print("% ");
Serial.print("Temperature:");
Serial.print(t);
Serial.print("°C / ");
Serial.print(f);
Serial.print("°F ");
Serial.print("Heat Index:");
Serial.print(hic);
Serial.print("°C / ");
Serial.print(hif);
Serial.println("°F ");
}
}