#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Konfigurasi LCD
LiquidCrystal_I2C lcd(0x27, 20, 4);
// Pin konfigurasi
#define PIR_PIN 14
#define LED_MERAH 16
#define LED_HIJAU 17
#define LED_BIRU 18
void setup() {
// Setup LCD
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Sistem Penceroboh");
// Setup pin
pinMode(PIR_PIN, INPUT);
pinMode(LED_MERAH, OUTPUT);
pinMode(LED_HIJAU, OUTPUT);
pinMode(LED_BIRU, OUTPUT);
// LED hijau menunjukkan sistem aktif
digitalWrite(LED_HIJAU, HIGH);
lcd.setCursor(0, 1);
lcd.print("Sistem Aktif");
delay(2000);
}
void loop() {
int motionDetected = digitalRead(PIR_PIN);
if (motionDetected) {
// Gerakan dikesan
digitalWrite(LED_MERAH, HIGH);
digitalWrite(LED_HIJAU, LOW);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("AMARAN: Penceroboh!");
delay(5000); // Tunggu 5 saat sebelum reset status
digitalWrite(LED_MERAH, LOW);
digitalWrite(LED_HIJAU, HIGH);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Sistem Aktif");
}
// LED biru berkedip untuk menunjukkan sistem dalam keadaan sedia
digitalWrite(LED_BIRU, HIGH);
delay(500);
digitalWrite(LED_BIRU, LOW);
delay(500);
}