/*
control street lights with PIR & LDR sensors
*/
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4); // set the LCD address to 0x27 for a 16 chars and 2 line display
#define LDR_PIN 2
int ldr=A0; //Set A0(Analog Input) for LDR.
int lux=300; // variable for reading the LDR status
int LED1PIN = 13; // choose the pin for LED1
int LED2PIN = 9; // choose the pin for LED2
int LED3PIN = 6; // choose the pin for LED3
int LED4PIN = 5; // choose the pin for LED4
int inputPin = 2; // choose the input pin (for PIR sensor)
int pirState = LOW; // we start, assuming no motion detected
int val = 0; // variable for reading the PIR status
void setup() {
pinMode(LDR_PIN, INPUT);
pinMode(5,OUTPUT); //LED1
pinMode(6,OUTPUT); //LED2
pinMode(9,OUTPUT); //LED3
pinMode(10,OUTPUT); //LED4
Serial.begin(9600);
lcd.init();
lcd.backlight();
}
void loop() {
lux=analogRead(ldr); //Reads the Value of LDR light
if (lux < 300)
{
lcd.setCursor(0, 0);
lcd.print("No Need Light!");
delay(1000);
}
else {
lcd.setCursor(0, 0);
lcd.print("**Light Ready**");
delay(1000);
val = digitalRead(inputPin); // read the value of PIR Motion Sensor
if (val == HIGH) { // check if the input is HIGH
lcd.setCursor(1, 1);
lcd.print("Motion Detected!");
digitalWrite(5,HIGH); //LED1 ON
digitalWrite(6,HIGH); //LED2 ON
delay(3000); //PROGRAMME WILL BE PAUSE FOR 3SEC
digitalWrite(5,LOW); //LED1 OFF
digitalWrite(6,HIGH); //LED2 ON
digitalWrite(9,HIGH); //LED3 ON
delay(3000); //PROGRAMME WILL BE PAUSE FOR 3SEC
digitalWrite(6,LOW); //LED2 OFF
digitalWrite(9,HIGH); //LED3 ON
digitalWrite(13,HIGH); //LED4 ON
delay(3000); //PROGRAMME WILL BE PAUSE FOR 3SEC
digitalWrite(9,LOW); //LED3 OFF
digitalWrite(13,LOW); //LED4 OFF
}
else {
lcd.setCursor(1, 1);
lcd.print("No Motion!");
delay(1000);
}
}
}