#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
const byte led1 = 9;
const byte led2 = 3;
const byte sensor1 = 12;
const byte sensor2 = 2;
int val1 = LOW;
int val2 = LOW;
int state1 = LOW;
int state2 = LOW;
void setup() {
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(sensor1, INPUT);
pinMode(sensor2, INPUT);
lcd.backlight();
lcd.init();
Serial.begin(9600);
}
void LCDon (String LEDon) {
lcd.setCursor(0, 0);
lcd.print("Motion Detected!");
lcd.setCursor(0, 1);
lcd.print("Street No.: ");
lcd.print(LEDon);
}
void loop() {
val1 = digitalRead(sensor1);
val2 = digitalRead(sensor2);
if (val1 == HIGH) {
digitalWrite(led1, HIGH);
if (state1 == LOW) {
LCDon("1");
state1 = HIGH;
}
}
else {
digitalWrite(led1, LOW);
if (state1 == HIGH) {
lcd.clear();
state1 = LOW;;
}
}
if (val2 == HIGH) {
digitalWrite(led2, HIGH);
if (state2 == LOW) {
LCDon("2");
state2 = HIGH;
}
}
else {
digitalWrite(led2, LOW);
if (state2 == HIGH) {
lcd.clear();
state2 = LOW;
}
}
if (val1 == HIGH) {
if (val2 == HIGH){
if (val1 == LOW){
if (val2 == HIGH){
lcd.clear();
state1 = LOW;
}
}
else{
if(val2==LOW){
if(val1==HIGH){
lcd.clear();
state2 = LOW;
}
}
else {
LCDon("1&2");
}
}
}
}
}