const int LDRPin = A0; // Analog pin connected to LDR-resistor junction
const int lightControlPin = 7; // Digital pin to control LED
int threshold = 600; // Threshold value to determine light or dark (adjust by calibration)
void setup() {
Serial.begin(9600);
pinMode(lightControlPin, OUTPUT);
}
void loop() {
int sensorValue = analogRead(LDRPin);
Serial.println(sensorValue);
if (sensorValue < threshold) { // Dark condition (LDR resistance high, voltage low)
digitalWrite(lightControlPin, HIGH); // Turn LED ON
} else {
digitalWrite(lightControlPin, LOW); // Turn LED OFF
}
delay(1000); // Wait 1 second before reading again
}