#include <LiquidCrystal_I2C.h>
#include <DHT.h>
#define LCD_ADDR 0x27
#define LCD_COlUMNS 16
#define LCD_ROWS 2
#define DHTPIN 7
#define DHTTYPE DHT22
#define BTNg 4
#define BTNr 2
bool show = false;
LiquidCrystal_I2C lcd(LCD_ADDR,LCD_COlUMNS,LCD_ROWS);
DHT dht(DHTPIN,DHTTYPE);
void setup() {
Serial.begin(15000);
pinMode(BTNg, INPUT_PULLUP);
pinMode(BTNr, INPUT_PULLUP);
lcd.begin(16,2);
lcd.init();
lcd.backlight();
dht.begin();
}
void loop() {
float rT = dht.readTemperature();
float rH = dht.readHumidity();
if(isnan(rT)||isnan(rH)){
Serial.println(F("Erorr"));
return;
}
bool BTNg_N = !digitalRead(BTNg);
bool BTNr_N = !digitalRead(BTNr);
if(BTNg_N){
show = true;
}
if(BTNr_N){
show = false;
}
if(show){
lcd.setCursor(0,0);
lcd.print("Temp_");
lcd.setCursor(5,0);
lcd.print(rT);
lcd.print(" c");
lcd.setCursor(0,1);
lcd.print("Hum_");
lcd.setCursor(4,1);
lcd.print(rH);
lcd.print(" %");
Serial.print("Temperatre: ");
Serial.print(rT);
Serial.print(F(" c"));
Serial.print("\n");
Serial.print("Humidity: ");
Serial.print(rH);
Serial.print(F(" %"));
Serial.print("\n");
}else{
lcd.clear();
}
}