const int LDRPin = A0; // Use analog pin for the LDR
const int ledPin = 13; // LED pin
int LDRValue = 0; // Variable to store the analog value from the LDR
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// Start serial communication for monitoring
Serial.begin(9600);
}
void loop() {
// Read the analog value from the LDR (0 to 1023):
LDRValue = analogRead(LDRPin);
// Print the value to the Serial Monitor:
Serial.print("LDR Value: ");
Serial.println(LDRValue);
// Set a threshold for light detection
if (LDRValue < 500) { // If the value is less than 500 (adjust as needed)
digitalWrite(ledPin, HIGH); // Turn LED on when it's dark
} else {
digitalWrite(ledPin, LOW); // Turn LED off when it's bright
}
delay(500); // Small delay for readability
}