int ldr_sensor = 35; // LDR sensor pin
int led = 2; // LED pin
void setup() {
Serial.begin(9600); // Initialize serial communication
analogSetAttenuation(ADC_11db); // Set ADC attenuation for LDR sensor
pinMode(led, OUTPUT); // Set LED pin as output
}
void loop() {
int ldrvalue = analogRead(ldr_sensor); // Read LDR sensor value
Serial.print("Ldr Value = "); // Print the LDR value
Serial.println(ldrvalue);
if (ldrvalue < 40) { // If the LDR value is less than 40 (very bright)
Serial.println(" => Very Bright");
digitalWrite(led, LOW); // Turn the LED off
} else if (ldrvalue < 800) { // If the LDR value is less than 800 (bright)
Serial.println(" => Bright");
digitalWrite(led, LOW); // Turn the LED off
} else if (ldrvalue < 2000) { // If the LDR value is less than 2000 (light)
Serial.println(" => Light");
digitalWrite(led, LOW); // Turn the LED off
} else if (ldrvalue < 3200) { // If the LDR value is less than 3200 (dim)
Serial.println(" => Dim");
digitalWrite(led, HIGH); // Turn the LED on
} else { // If the LDR value is greater than or equal to 3200 (dark)
Serial.println(" => Dark");
digitalWrite(led, HIGH); // Turn the LED on
}
delay(1000); // Wait for 1 second before the next loop
}