int LDRPin = 13; // LDR connected to analog pin A0
int LEDPin = 2; // LED connected to digital pin 13
int threshold = 500; // Threshold value for light level (adjust as needed)
void setup() {
pinMode(LDRPin, INPUT); // Set LDR pin as input
pinMode(LEDPin, OUTPUT); // Set LED pin as output
Serial.begin(9600); // Initialize serial communication for debugging
}
void loop() {
int LDRValue = analogRead(LDRPin); // Read the value from the LDR
Serial.println(LDRValue); // Print the LDR value to the Serial Monitor for debugging
if (LDRValue < threshold) {
// If the light level is below the threshold, turn on the LED
digitalWrite(LEDPin, HIGH);
} else {
// If the light level is above the threshold, turn off the LED
digitalWrite(LEDPin, LOW);
}
delay(100); // Small delay for stability
}