// Import the libraries
#include <LiquidCrystal_I2C.h>
#include <DHT.h>
// Define the various parts
// Liquid Crystal Display
#define I2C_ADDR 0x27
#define LCD_COLUMNS 16
#define LCD_LINES 2
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_LINES);
// DHT Sensor
#define DHTPIN 2
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
void setup() {
// Setup the parts
// Liquid Crystal Display
lcd.init();
lcd.backlight();
lcd.print("Loading");
// DHT
dht.begin();
// allow all systems to load
delay(1000);
// clear the lcd screen for the program to load
lcd.clear();
}
void loop() {
// Call the first sensor
TempHumRead();
}
void TempHumRead() {
// read the humidity
float Hum = dht.readHumidity();
// read the temperature and compute the heat index (Celcius)
float TempC = dht.readTemperature();
float HiC = dht.computeHeatIndex(TempC, Hum, false);
// conversion to Farenheit and compute the heat index
float TempF = ((TempC*9/5)+32);
float HiF = dht.computeHeatIndex(TempF, Hum);
// Print to the screen
lcd.clear();
lcd.setCursor( 1, 0);
lcd.print("Temp:");
lcd.setCursor( 7, 0);
lcd.print(TempC);
lcd.setCursor( 14, 0);
lcd.print("C");
lcd.setCursor( 1, 1);
lcd.print("Hum:");
lcd.setCursor( 7, 1);
lcd.print(Hum);
lcd.setCursor( 14, 1);
lcd.print("%");
// delay for heat index cycling
delay(2500);
// print the heat index
lcd.clear();
lcd.setCursor( 1, 0);
lcd.print("Heat Index:");
lcd.setCursor( 1, 1);
lcd.print(HiC);
lcd.setCursor( 7, 1);
lcd.print("C");
// delay for reset
delay(2500);
}