#include <DHTesp.h>
#include <LiquidCrystal_I2C.h>
const int DHT_PIN = 15;
LiquidCrystal_I2C lcd(0x27,20,4);
DHTesp dhtSensor;
#define merah 19
#define biru 4
#define kuning 5
#define buzz 14
void setup() {
Serial.begin(115200);
dhtSensor.setup(DHT_PIN, DHTesp :: DHT22);
pinMode(merah,OUTPUT);
pinMode(biru, OUTPUT);
pinMode(kuning, OUTPUT);
noTone(buzz);
lcd.init();
lcd.backlight();
}
void loop() {
delay(2000);
float humidity = dhtSensor.getHumidity();
float temperature = dhtSensor.getTemperature();
if(temperature<30 && humidity<30){
digitalWrite(merah, LOW);
digitalWrite(biru, HIGH);
digitalWrite(kuning, LOW);
tone(buzz, 1000);
delay(400);
noTone(buzz);
} else if(temperature<50 && humidity<50){
digitalWrite(merah, LOW);
digitalWrite(biru, HIGH);
digitalWrite(kuning, HIGH);
tone(buzz, 1000);
delay(400);
noTone(buzz);
} else if(temperature<70 && humidity<70){
digitalWrite(merah, LOW);
digitalWrite(biru, HIGH);
digitalWrite(kuning, HIGH);
tone(buzz, 1000);
delay(400);
noTone(buzz);
} else if(temperature>70 && humidity>70){
digitalWrite(merah, HIGH);
digitalWrite(biru, HIGH);
digitalWrite(kuning, HIGH);
tone(buzz, 1000);
delay(400);
noTone(buzz);
} else{
digitalWrite(merah, LOW);
digitalWrite(biru, LOW);
digitalWrite(kuning, LOW);
noTone(buzz);
}
lcd.setCursor(0,0);
lcd.print("Kelembapan: ");
lcd.print(humidity);
lcd.println("%");
lcd.setCursor(0,1);
lcd.print("Suhu : ");
lcd.print(temperature);
lcd.println("C");
Serial.print("Kelembapan: ");
Serial.print(humidity, 1);
Serial.println("%");
Serial.print("Suhu : ");
Serial.print(temperature, 1);
Serial.println("C");
}