#define DHTPIN 5
#define DHTTYPE DHT22
Servo servo;
DHT dht(DHTPIN, DHTTYPE);
#include <LiquidCrystal_I2C.h> 
const int buzzer = 4;
#include <Servo.h>
#include "DHT.h" 
LiquidCrystal_I2C lcd(0x27, 16, 2);

void setup() {
Serial.begin (115200);
servo.attach(3);
dht.begin();
pinMode(7, OUTPUT);
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
lcd.init(); // initialize the lcd
lcd.backlight();
pinMode(buzzer, OUTPUT);
}

void loop() {
float hum = dht.readHumidity(); 
float temp = dht.readTemperature(); 
// di dalam wokwi dht tersetting maksimal 80 derajat menjadikan saya menurunkan
// derajatnya agar dapat di simulasikan lebih baik
if (temp < 65 ){
  digitalWrite(7, LOW);
  digitalWrite(8,LOW);
  digitalWrite(9,HIGH);
  lcd.clear(); 
  lcd.setCursor(0, 0);
  lcd.print("SUHU: " + (String)temp + " *C");
  lcd.setCursor(0, 1);
  lcd.print("Humidity: " + (String)hum + "%");
  servo.write(0);
  digitalWrite(buzzer, LOW);
  noTone(buzzer);
  delay(1000);

} else if (temp <= 75){
  digitalWrite(7, LOW);
  digitalWrite(8,HIGH);
  digitalWrite(9,LOW);
  lcd.clear(); 
  lcd.setCursor(0, 0);
  lcd.print("SUHU: " + (String)temp + " *C");
  lcd.setCursor(0, 1);
  lcd.print("Humidity: " + (String)hum + " %");
  servo.write(0);
  digitalWrite(buzzer, LOW);
  noTone(buzzer);
  delay(1000);
  
} else if (temp > 75){
  digitalWrite(7, HIGH);
  digitalWrite(8,LOW);
  digitalWrite(9,LOW);
  lcd.clear(); 
  lcd.setCursor(0, 0);
  lcd.print("SUHU: " + (String)temp + " *C");
  lcd.setCursor(0, 1);
  lcd.print("Humidity: " + (String)hum + " %");
  servo.write(90);
  digitalWrite(buzzer, HIGH);
  tone(buzzer, 1000);
  delay(1000);
}
}