#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
const int relay1 = 5;
const int relay2 = 4;
int val1 = 0;
int val2 = 0;
int sensor1 = 3;
int sensor2 = 2;
int state1 = LOW;
int state2 = LOW;
void setup() {
Serial.begin(9600);
lcd.init();
pinMode(relay1, OUTPUT);
pinMode(relay2, OUTPUT);
pinMode(sensor1, INPUT);
pinMode(sensor2, INPUT);
lcd.backlight();
}
void loop() {
val1 = digitalRead(sensor1);
val2 = digitalRead(sensor2);
if(val1==1){
digitalWrite(relay1,1);
if(state1==LOW){
lcd.setCursor(0,0);
lcd.print("MOTION DETECTED:");
lcd.setCursor(0,1);
lcd.print("STREETLIGHT #1");
state1 = HIGH;
}
} else {
digitalWrite(relay1,0);
if(state1==HIGH){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("MOTION STOPPED:");
lcd.setCursor(0,1);
lcd.print("STREETLIGHT #1");
state1 = LOW;
}
}
if(val2==1){
digitalWrite(relay2,1);
if(state2==LOW){
lcd.setCursor(0,0);
lcd.print("MOTION DETECTED:");
lcd.setCursor(0,1);
lcd.print("STREETLIGHT #2");
state2 = HIGH;
}
} else {
digitalWrite(relay2,0);
if(state2==HIGH){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("MOTION STOPPED:");
lcd.setCursor(0,1);
lcd.print("STREETLIGHT #2");
state2 = LOW;
}
}
if(val1==HIGH && val2==HIGH){
lcd.setCursor(0,0);
lcd.print("MOTION DETECTED:");
lcd.setCursor(0,1);
lcd.print("STREELIGHT #1&2");
}
}