#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd (0x27, 16, 2);
int pir = 8;
int led = 6;
int pirval = 0;
int state = LOW;
void setup() {
Serial.begin(9600);
pinMode (pir, INPUT);
pinMode (led, OUTPUT);
lcd.init();
lcd.backlight();
lcd.setCursor(2,0);
lcd.print("KELOMPOK C-3");
lcd.setCursor(1,1);
lcd.print("MINI PROJECT 5");
delay(2000);
lcd.clear();
lcd.setCursor (2,0);
lcd.print("KELOMPOK C-3");
lcd.setCursor(0,1);
lcd.print("PENDETEKSI GERAK");
delay(2000);
}
void loop() {
pirval = digitalRead(pir);
if (pirval == HIGH){
delay(100);
if (state == HIGH){
Serial.println ("Motion Detected");
lcd.clear();
lcd.setCursor(5,0);
lcd.print("MOTION");
lcd.setCursor(4,1);
lcd.print("DETECTED");
delay(1500);
lcd.clear();
lcd.setCursor(2,0);
lcd.print("TURN ON LAMP");
digitalWrite(led, HIGH);
state = LOW;
}
}
else
{
//digitalWrite(redled, HIGH);
delay(200);
if (state == LOW){
Serial.println ("Motion Stopped");
state = HIGH;
lcd.clear();
lcd.setCursor(3,0);
lcd.print("NO MOTION");
lcd.setCursor(4,1);
lcd.print("DETECTED");
delay(1500);
lcd.clear();
lcd.setCursor(1,0);
lcd.print("TURN OFF LAMP");
digitalWrite(led, LOW);
}
}
}