#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
int BIRU = 12; // choose the pin for the LED Biru
int MERAH = 13; // choose the pin for the LED Merah
int inputPin = 2; // choose the input pin (for PIR sensor)
int val = 0; // variable for reading the pin status
void setup() {
// put your setup code here, to run once:
pinMode(BIRU, OUTPUT); // declare LED as output BIRU
pinMode(MERAH, OUTPUT); // declare LED as output MERAH
pinMode(inputPin, INPUT); // declare sensor as input
Serial.begin(9600);
Serial.println("Selamat Datang di Sistem pendeteksi gerakan");
lcd.init();
lcd.backlight();
lcd.setCursor(0,0);
lcd.print("Rendy A A P");
lcd.setCursor(0,1);
lcd.print("Sensor Gerak= ON");
delay(5000); // this speeds up the simulation
}
void loop() {
// put your main code here, to run repeatedly:
val = digitalRead(inputPin); // read input value
if (val == HIGH) { // check if the input is HIGH
digitalWrite(BIRU, LOW); // turn LED OFF
digitalWrite(MERAH, HIGH); // turn LED ON
Serial.print("Peringatan= ");
Serial.println("HATI-HATI AWAS ADA GERAKAN !!!");
lcd.setCursor(0,1);
lcd.print(" ADA GERAKAN !!!");
} else {
digitalWrite(BIRU, HIGH); // turn LED ON
digitalWrite(MERAH, LOW); // turn LED OFF
Serial.print("Status= ");
Serial.println("Tidak ada gerakan terdeteksi");
lcd.setCursor(0,0);
lcd.print("Sensor Gerak = ");
lcd.setCursor(0,1);
lcd.print("Terpantau Aman ");
}
delay(2000); // this speeds up the simulation
}