#include <LiquidCrystal.h>
#define LDR_PIN A0 // Use analog pin for LDR
#define LED_PIN 9 // Use LED to simulate bulb
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
void setup() {
// Initialize LCD
lcd.begin(16, 2);
lcd.print("Initialising:");
delay(2000);
lcd.clear();
// Set up the pins
pinMode(LDR_PIN, INPUT);
pinMode(LED_PIN, OUTPUT); // LED pin as output
}
void loop() {
// Read LDR value (0-1023 from analog pin)
int ldrValue = analogRead(LDR_PIN);
// Debug: Show LDR value on LCD
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("LDR Value: ");
lcd.print(ldrValue);
// Define a threshold for brightness (e.g., below 500 is dark)
int threshold = 500; // You may need to adjust this threshold
// Debugging: Print threshold status
lcd.setCursor(0, 1);
if (ldrValue < threshold) {
digitalWrite(LED_PIN, HIGH); // Turn LED ON
lcd.print("Light ON ");
} else {
digitalWrite(LED_PIN, LOW); // Turn LED OFF
lcd.print("Light OFF");
}
delay(500);
}