#include <LiquidCrystal_I2C.h>

const int ldrPin = A0;  
const int pirPin = 3;    
const int ledPin = 2;  

LiquidCrystal_I2C lcd(0x27, 16, 2);  

void setup() {
  pinMode(ldrPin, INPUT);
  pinMode(pirPin, INPUT);
  pinMode(ledPin, OUTPUT);

  lcd.begin(16, 2);
  lcd.print("Gerakan: ");
  
  Serial.begin(9600);
}

void loop() {
  int ldrValue = analogRead(ldrPin);
  int pirValue = digitalRead(pirPin);

  // Ambil bacaan sensor LDR dan PIR
  Serial.print("LDR Value: ");
  Serial.print(ldrValue);
  Serial.print(" | PIR Value: ");
  Serial.println(pirValue);

  lcd.setCursor(0, 1);
  lcd.print("LDR: ");
  lcd.print(ldrValue);

 
  if (pirValue == HIGH && ldrValue < 500) {
    digitalWrite(ledPin, HIGH); 
    lcd.setCursor(9, 0);
    lcd.print("Gerakan");
    Serial.println("Gerakan terdeteksi pada malam hari!");
  } else {
    digitalWrite(ledPin, LOW); 
    lcd.setCursor(9, 0);
    lcd.print("Tidak ada");
  }

  delay(500); 
}