#include <LiquidCrystal_I2C.h>
#include "DHT.h"
#define DHTPIN 2
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal_I2C lcd(0x27,20,4);
void setup() {
Serial.begin(9600);
Serial.println("DHT22 Testprogramm");
dht.begin();
}
void loop() {
delay(2000);
float h = dht.readHumidity();
float t = dht.readTemperature();
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Humidity: ");
lcd.print(h);
lcd.println("%");
lcd.setCursor(0,1);
lcd.print("Temperatur: ");
lcd.print(t);
lcd.println("C");
if (isnan(h) || isnan(t)) {
lcd.setCursor(0,0);
lcd.println(" ");
lcd.setCursor(0,1);
lcd.println(" Fehler! ");
return;
}
Serial.print("Humidity: ");
Serial.print(h);
Serial.print("%\t");
Serial.print("Temperatur: ");
Serial.print(t);
Serial.println("C");
}