const int ldrPin = A0; // Analog pin for LDR
const int ledPin = 4; // Digital pin for LED
void setup() {
pinMode(ledPin, OUTPUT); // Set the LED pin as an output
Serial.begin(9600); // Optional: If you want to monitor LDR values in the Serial Monitor
}
void loop() {
int ldrValue = analogRead(ldrPin); // Read the LDR value
Serial.print("LDR Value: ");
Serial.println(ldrValue); // Optional: Print the LDR value to the Serial Monitor
if (ldrValue < 300) {
digitalWrite(ledPin, HIGH); // Turn on the LED
} else {
digitalWrite(ledPin, LOW); // Turn off the LED
}
delay(500); // Optional: Add a delay to make the changes visible
}