/*********************************************************************
* TEMPERATURE AND HUMIDITY SENSOR USING DHT11/22, ESP32, AND LCD I2C *
* SUBMITTED BY: MURILLO, CYRIL C *
* SUBMITTED TO: PROF. MICHAEL T. SAMONTE *
* *******************************************************************/
#include <DHT.h>
#include <LiquidCrystal_I2C.h>
const int DHT_Pin =4;
float temperature ;
float humidity ;
int totalColumns =16; //total columns in I2C
int totalRows = 2; //rows in our I2C
DHT dht(DHT_Pin, DHT22); // change 22 to 11 if using DHT11
LiquidCrystal_I2C lcd (0x27, totalColumns, totalRows);
void setup ()
{
Serial.begin(9600);
lcd.init();
lcd.backlight();
lcd.clear();
lcd.setCursor(2, 0);
}
void loop ()
{
float humi = dht.readHumidity(); // read humid
float tempC = dht.readTemperature(); // read temp
lcd.clear();
if (isnan(tempC) || isnan(humi))
{
lcd.setCursor(0, 0);
lcd.print("Error");
}
else
{
lcd.setCursor(0, 0); // display position
lcd.print("Temp "); //print temp
lcd.print(tempC);
lcd.print(" Cels");
lcd.setCursor(0, 1); // display position
lcd.print("Humid: "); // print humid
lcd.print(humi);
lcd.print("%");
}
delay (2000); // delay 2 seconds
}