#include <Wire.h>
#include <DHT.h>
#include <LiquidCrystal_I2C.h>
#define sda 21
#define scl 22
#define ldrPin 26
#define pirPin 2
#define dhtPin 13
#define trigPin 12
#define echoPin 14
#define ledPin 15
#define Relay 4
#define DHTTYPE DHT22
LiquidCrystal_I2C lcd(0x27, 16, 2);
float durasi, jarak;
float hum;
float temp;
DHT dht(dhtPin, DHT22);
void setup(){
Serial.begin(115200);
lcd.init();
lcd.backlight();
dht.begin();
pinMode(pirPin, INPUT);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(Relay, OUTPUT);
pinMode(ldrPin, INPUT);
pinMode(ledPin, OUTPUT);
}
void loop() {
hum = dht.readHumidity();
temp = dht.readTemperature();
int LDRValue = analogRead(ldrPin);
if (LDRValue > 800) {
digitalWrite(ledPin, HIGH);
}
else{
digitalWrite(ledPin, LOW);
}
digitalWrite(trigPin, HIGH);
digitalWrite(trigPin, LOW);
durasi = pulseIn(echoPin, HIGH);
jarak = 0.017 * durasi;
if (jarak < 50) {
digitalWrite(Relay,HIGH);
}
else if(jarak > 130){
digitalWrite(Relay,LOW);
}
Serial.print("Lembab: ");
Serial.println(hum);
Serial.print("Suhu: ");
Serial.println(temp);
lcd.setCursor(3,0);
lcd.print("Papan Informasi");
//suhu
lcd.setCursor(0,1);
lcd.print("Suhu :");
lcd.setCursor(13,1);
lcd.print(temp);
lcd.setCursor(19,1);
lcd.print("C");
//kelembaban
lcd.setCursor(0,2);
lcd.print("Kelembaban :");
lcd.setCursor(13,2);
lcd.print(hum);
lcd.setCursor(19,2);
lcd.print("%");
delay(1000);
}