// Required Libraries
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Define the I2C address of the LCD
#define I2C_ADDR 0x27
// Initialize the LCD
LiquidCrystal_I2C lcd(I2C_ADDR, 16, 2);
// Define the LED pins
int ledPins[4] = {6, 7, 8, 9};
void setup() {
// Initialize the LCD connected to the I2C
lcd.begin(16, 2);
// Initialize the LDR sensors connected to A0, A1, A2, A3
pinMode(A0, INPUT);
pinMode(A1, INPUT);
pinMode(A2, INPUT);
pinMode(A3, INPUT);
// Initialize the IR sensors connected to digital pins 2, 3, 4, 5
pinMode(2, INPUT);
pinMode(3, INPUT);
pinMode(4, INPUT);
pinMode(5, INPUT);
// Initialize the LED lights connected to digital pins 6, 7, 8, 9
for (int i = 0; i < 4; i++) {
pinMode(ledPins[i], OUTPUT);
}
}
void loop() {
// Read the values from the LDR and IR sensors
int ldrValues[4] = {analogRead(A0), analogRead(A1), analogRead(A2), analogRead(A3)};
int irValues[4] = {digitalRead(2), digitalRead(3), digitalRead(4), digitalRead(5)};
// Control the LED lights based on the IR sensor values
for (int i = 0; i < 4; i++) {
if (irValues[i] == HIGH) { // If movement is detected
digitalWrite(ledPins[i], HIGH); // Turn on the LED
} else {
// Reduce the intensity of the LED light
// You can adjust the value to change the intensity as needed
analogWrite(ledPins[i], 127); // Half intensity
}
}
// Display the values on the LCD
lcd.clear();
for (int i = 0; i < 4; i++) {
lcd.setCursor(0, 0);
lcd.print("Street Light ");
lcd.print(i+1);
lcd.setCursor(0, 1);
lcd.print("LDR: ");
lcd.print(ldrValues[i]);
lcd.print(" IR: ");
lcd.print(irValues[i] == HIGH ? "Movement" : "No Movement");
delay(3000); // Wait for 3 seconds before displaying the next set of values
}
}