const int LDR_PIN = 34; // LDR is connected to GPIO34 (analog pin)
const int LED_PIN = 23; // LED is connected to GPIO23 (digital pin)
int LDR_value = 0; // Variable to store LDR value
int threshold = 1000; // Threshold for light intensity (adjust as needed)
void setup() {
Serial.begin(115200); // Initialize serial communication
pinMode(LED_PIN, OUTPUT); // Set LED pin as an output
}
void loop() {
LDR_value = analogRead(LDR_PIN); // Read the value from the LDR sensor
Serial.println(LDR_value); // Print the LDR value to the Serial Monitor
if (LDR_value < threshold) { // If light intensity is low
digitalWrite(LED_PIN, HIGH); // Turn on the LED
} else { // If light intensity is high
digitalWrite(LED_PIN, LOW); // Turn off the LED
}
delay(1000); // Delay for half a second before reading again
}