#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd (0x27,16,2);
const int pirPin1 = 6;
const int pirPin2 = 7;
const int relay1 = 2;
const int relay2 = 4;
int masuk = 0,keluar=0,total = 0;
void setup() {
// put your setup code here, to run once:
pinMode(pirPin1, INPUT);pinMode(pirPin2, INPUT);
pinMode(relay1,OUTPUT);pinMode(relay2, OUTPUT);
lcd.init();
lcd.backlight();
}
void loop()
// put your main code here, to run repeatedly:
{
if (digitalRead(pirPin1))
{
total++;
masuk = masuk + 1;
delay(1000);
}
if (digitalRead(pirPin2))
{
total--;
keluar = keluar + 1;
delay(1000);
}
if (total>10){
digitalWrite(relay1, HIGH);
digitalWrite(relay2, HIGH);
delay(1000);
}
else
{
digitalWrite(relay1, HIGH);
digitalWrite(relay2, LOW);
}
lcd.clear();
lcd.setCursor(1,0);
lcd.print(" Pengunjung ");
lcd.setCursor(0,1);
lcd.print("M: ");
lcd.setCursor(2,1);
lcd.print(masuk);
lcd.setCursor(6,1);
lcd.print("K :");
lcd.setCursor(18,1);
lcd.print(keluar);
lcd.setCursor(11,1);
lcd.print("T: ");
lcd.setCursor(13,1);
lcd.print(total);
delay(1000);
}