const int Switch = 4;
const int relay = 13;
const int Sensor = 7;
int buttonstate=0;
int lastbuttonstate=0;
int buttonPushCounter=0;
int SensorValue;
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
pinMode(Switch, INPUT);
pinMode(Sensor, INPUT);
pinMode(relay, OUTPUT);
}
void loop(){
/////////////////////////////button///////////////////////////////
buttonstate = digitalRead(Switch);
if(buttonstate != lastbuttonstate){
if(buttonstate == HIGH){
buttonPushCounter += 1;
}
delay(5);
}
lastbuttonstate = buttonstate;
/////////////////////////////Sensor///////////////////////////////
SensorValue = digitalRead(Sensor);
if(buttonPushCounter && SensorValue == 1){
digitalWrite(relay,HIGH);
HAVE();
}
if(buttonPushCounter && SensorValue == 0){
digitalWrite(relay,LOW);
NON();
}
}
void HAVE(){
lcd.init();
lcd.backlight();
lcd.setCursor(2, 2);
lcd.print("intruder");
}
void NON(){
lcd.init();
lcd.backlight();
lcd.setCursor(2, 2);
lcd.print("secured");
}