#define pitch 262
int led =2;
int sensor=13;
int state=LOW;
int val= 0;
int buzzer=10;
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
void setup() {
// put your setup code here, to run once:
pinMode(led, OUTPUT);
pinMode(sensor, INPUT);
pinMode(buzzer, OUTPUT);
Serial.begin(9600);
lcd.begin(16, 2);
// you can now interact with the LCD, e.g.:
lcd.print("Security On");
}
void loop() {
// put your main code here, to run repeatedly:
val= digitalRead(sensor);
if(val==HIGH){
digitalWrite(led, HIGH);
tone(buzzer,pitch);
delay(1000);
if(state== LOW){
//Serial.println("Motion detected!!");
state=HIGH;
lcd.begin(16, 2);
// you can now interact with the LCD, e.g.:
lcd.print("High RISK!!");
}
}
else{
digitalWrite(led,LOW);
noTone(buzzer);
delay(2000);
if(state==HIGH){
Serial.println("Motion Stopped");
lcd.begin(16, 2);
// you can now interact with the LCD, e.g.:
lcd.print("LOW RISK");
}
}
}