#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
}
}