#include <DHT.h>
#include <Adafruit_Sensor.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
#define DHTPIN 25
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("DHTxx Test!!!");
dht.begin();
lcd.init(); // initialize the lcd
lcd.backlight();
}
void loop() {
// put your main code here, to run repeatedly:
delay(2000); // this speeds up the simulation
float h = dht.readHumidity();
float t = dht.readTemperature();
float f = dht.readTemperature(true);
if (isnan(h) | isnan(t) | isnan(f)){
Serial.println("Failed to read Sensor!");
return;
}
float hif = dht.computeHeatIndex(f, h);
float hic = dht.computeHeatIndex(t, h, false);
Serial.println("Humidity: ");
Serial.println(h);
Serial.println("°F Heat Index: ");
Serial.println(hic);
lcd.clear(); // clear display
lcd.setCursor(4, 0); // move cursor to (0, 0)
lcd.print("Humidity"); // print message at (0, 0)
lcd.setCursor(5, 1); // move cursor to (2, 1)
lcd.print(h);
delay(2000); // this speeds up the simulation
lcd.clear(); // clear display
lcd.setCursor(3, 0); // move cursor to (0, 0)
lcd.print("Heat Index"); // print message at (0, 0)
lcd.setCursor(5, 1); // move cursor to (2, 1)
lcd.print(hic);
}