#include <LiquidCrystal.h>
// Define the pins for the LDRs
const int LDR1_Pin = A0;
const int LDR2_Pin = A3;
const int LDR3_Pin = A5;
// Define the pins for the LED indicators
const int LED1_Pin = 6;
const int LED2_Pin = 7;
const int LED3_Pin = 8;
// Define the threshold values for fault detection
const int threshold = 500; // Adjust this value based on ambient light conditions
// Initialize the LCD library
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
// Set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("Street Lights:");
// Set LED pins as outputs
pinMode(LED1_Pin, OUTPUT);
pinMode(LED2_Pin, OUTPUT);
pinMode(LED3_Pin, OUTPUT);
}
void loop() {
// Read analog values from LDRs
int LDR1_value = analogRead(LDR1_Pin);
int LDR2_value = analogRead(LDR2_Pin);
int LDR3_value = analogRead(LDR3_Pin);
// Check if each LDR reading is below the threshold
bool LDR1_fault = LDR1_value < threshold;
bool LDR2_fault = LDR2_value < threshold;
bool LDR3_fault = LDR3_value < threshold;
// Display status on LCD
lcd.setCursor(0, 1);
lcd.print("L1:");
lcd.print(LDR1_fault ? "F " : "G ");
lcd.setCursor(6, 1);
lcd.print("L2:");
lcd.print(LDR2_fault ? "F " : "G ");
lcd.setCursor(12, 1);
lcd.print("L3:");
lcd.print(LDR3_fault ? "F " : "G ");
// Turn on respective LED indicators for faults
digitalWrite(LED1_Pin, LDR1_fault ? HIGH : LOW);
digitalWrite(LED2_Pin, LDR2_fault ? HIGH : LOW);
digitalWrite(LED3_Pin, LDR3_fault ? HIGH : LOW);
delay(1000); // Adjust delay as needed
}