// 🌙 Automatic LED Light using LDR
const int LDR_PIN = A0; // LDR connected to analog pin A0
const int LED_PIN = 9; // LED connected to digital pin 9
int ldrValue = 0; // Variable to store LDR reading
int threshold = 500; // Light threshold (adjust based on your room lighting)
void setup() {
pinMode(LED_PIN, OUTPUT);
Serial.begin(9600); // For debugging light values
}
void loop() {
ldrValue = analogRead(LDR_PIN); // Read LDR value
Serial.println(ldrValue); // Print value to Serial Monitor
if (ldrValue < threshold) {
digitalWrite(LED_PIN, HIGH); // Turn ON LED in dark
} else {
digitalWrite(LED_PIN, LOW); // Turn OFF LED in light
}
delay(500); // Small delay for stability
}