#include "DHT.h"
#define DHTTYPE DHT22   

#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);

#include <Servo.h>
Servo servo;

const int DHTPin = 5;     
DHT dht(DHTPin, DHTTYPE);

void setup() {
  lcd.init();
  lcd.backlight();
  Serial.begin(9600);
  Serial.println("Start Sensor Suhu");
  dht.begin();

  servo.attach(3);
  servo.write(0);
}

void loop() {
  delay(800);
  float hmd = dht.readHumidity();
  float temp = dht.readTemperature();

  // Keterangan Suhu dan Kelembapan
  Serial.print("Humidity: ");
  Serial.print(hmd);
  Serial.print(" %\t");
  Serial.print("Temperature: ");
  Serial.print(temp);
  Serial.println(" *C "); 
  
  // Informasi suhu
  lcd.setCursor(0, 0); 
  lcd.print("Temp");
  lcd.setCursor(7, 0); 
  lcd.print(temp);
 
  // Informasi kelembapan
  lcd.setCursor(0, 1); 
  lcd.print("Hmdty");
  lcd.setCursor(7, 1); 
  lcd.print(hmd);

  if (temp > 70) {
    servo.write(180);
  } else if (temp > 40) {
    servo.write(90);
  } else {
    servo.write(0);
  }

}