#include "DHT.h"
#include "LiquidCrystal_I2C.h"

#define DHTPIN 2     
#define DHTTYPE DHT22   
DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal_I2C lcd(0x27, 20, 4);
#define relay  5

void setup() {
  //Serial.begin(9600);
  //Serial.println(F("DHTxx test!"));
  dht.begin();
  lcd.init();
  lcd.backlight();
  pinMode(relay, OUTPUT);
}

void loop() {
  delay(2000);
  
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  float f = dht.readTemperature(true);
  if (isnan(h) || isnan(t) || isnan(f)) {
    lcd.print(F("Failed to read from DHT sensor!"));
    return;
  }
 
  float hif = dht.computeHeatIndex(f, h);
  float hic = dht.computeHeatIndex(t, h, false);

  lcd.setCursor(0, 0);
  lcd.print(F("Kelembaban:"));
  lcd.print(h);
  lcd.print("%");

   lcd.setCursor(0, 1);
  lcd.print(F("Suhu:"));
  lcd.print(t);
  //lcd.print("       ");
  lcd.print("*C ");
  
  delay(100);
  /*
  Serial.print(F("°C "));
  Serial.print(f);
  Serial.print(F("°F  Heat index: "));
  Serial.print(hic);
  Serial.print(F("°C "));
  Serial.print(hif);
  Serial.println(F("°F"));*/




  if ( h > 80.10){ //jika kelembaban lebih besar dari 80.10
    digitalWrite(relay, LOW); //relay menyala
  }
  else if( t > 30.10){ //jika suhu lebih besar dari 30.10 
    digitalWrite(relay, LOW); //relay menyala
  }
  else{ //jika tidak 
    digitalWrite(relay, HIGH); //relay mati
  }

}
uno:A5.2
uno:A4.2
uno:AREF
uno:GND.1
uno:13
uno:12
uno:11
uno:10
uno:9
uno:8
uno:7
uno:6
uno:5
uno:4
uno:3
uno:2
uno:1
uno:0
uno:IOREF
uno:RESET
uno:3.3V
uno:5V
uno:GND.2
uno:GND.3
uno:VIN
uno:A0
uno:A1
uno:A2
uno:A3
uno:A4
uno:A5
dht1:VCC
dht1:SDA
dht1:NC
dht1:GND
lcd1:GND
lcd1:VCC
lcd1:SDA
lcd1:SCL
relay1:NO2
relay1:NC2
relay1:P2
relay1:COIL2
relay1:NO1
relay1:NC1
relay1:P1
relay1:COIL1
led1:A
led1:C
r1:1
r1:2