const int LDR_PIN = A0; // LDR pin connected to analog pin A0
const int LED_PIN = 9; // LED pin connected to digital pin 9
void setup() {
pinMode(LDR_PIN, INPUT);
pinMode(LED_PIN, OUTPUT);
}
void loop() {
int lightValue = analogRead(LDR_PIN); // Read the value from LDR
if (lightValue > 500) { // Adjust this threshold according to your ambient light conditions
digitalWrite(LED_PIN, HIGH); // Turn on LED when it's dark
} else {
digitalWrite(LED_PIN, LOW); // Turn off LED when it's bright
}
delay(100); // Delay for stability
}