// Pin connected to the LDR
const int ldrPin = A0;
// Pin connected to the LED
const int ledPin = 9;
void setup() {
pinMode(ledPin, OUTPUT); // Set LED pin as output
Serial.begin(9600); // Initialize serial communication
}
void loop() {
int ldrValue = analogRead(ldrPin); // Read the value from the LDR
Serial.println(ldrValue); // Print the value to the serial monitor
// Threshold value to turn on/off the LED
int threshold = 500;
if (ldrValue < threshold) {
digitalWrite(ledPin, HIGH); // Turn on the LED
} else {
digitalWrite(ledPin, LOW); // Turn off the LED
}
delay(500); // Wait for a short time before taking the next reading
}