const int LDR_PIN = A0; // LDR pin
const int LED_PIN = 9; // LED pin
int lightThreshold = 500; // Light intensity threshold
void setup() {
pinMode(LED_PIN, OUTPUT); // Set LED as output
Serial.begin(9600); // Initialize serial communication
}
void loop() {
int lightValue = analogRead(LDR_PIN); // Read LDR value
Serial.print("Light Value: ");
Serial.println(lightValue); // Print light value to Serial Monitor
if (lightValue < lightThreshold) {
digitalWrite(LED_PIN, HIGH); // Turn on LED if light is low
} else {
digitalWrite(LED_PIN, LOW); // Turn off LED if light is high
}
delay(500); // Small delay to avoid rapid updates
}