const int ldrPin = A0; // LDR connected to analog pin A0
const int ledPin = 9; // LED connected to digital pin 9
const int threshold = 500; // Light threshold value
void setup() {
pinMode(ledPin, OUTPUT); // Set LED pin as output
Serial.begin(9600); // Initialize serial communication
}
void loop() {
int ldrValue = analogRead(ldrPin); // Read LDR value
// Print the value to the Serial Monitor
Serial.print("LDR Value: ");
Serial.println(ldrValue);
// Control LED based on light intensity
if (ldrValue < threshold) {
digitalWrite(ledPin, HIGH); // Turn LED ON
} else {
digitalWrite(ledPin, LOW); // Turn LED OFF
}
delay(500); // Delay for stability
}