// Define the analog pin for LDR
const int LDRpin = A0;
void setup() {
pinMode(8, OUTPUT); // LED Pin
Serial.begin(9600); // Initialize serial communication
}
void loop() {
// Read the analog value from LDR
int LDRvalue = analogRead(LDRpin);
// Print the analog value to the serial monitor
Serial.print("LDR Value: ");
Serial.println(LDRvalue);
// Optional: You can add a delay to slow down the serial output
delay(300);
// Connecting LED with condition
if (LDRvalue < 400) {
digitalWrite(8, HIGH); // Turn LED ON
Serial.println("LED ON");
}
else {
digitalWrite(8, LOW); // Turn LED OFF
Serial.println("LED OFF");
}
}