const int LDR_PIN = A0; // Connect the LDR to analog pin A0
const int LED_PIN = 9; // Connect an LED to digital pin 9
void setup() {
pinMode(LED_PIN, OUTPUT);
Serial.begin(9600);
}
void loop() {
int ldrValue = analogRead(LDR_PIN); // Read the analog voltage from the LDR
int brightness = map(ldrValue, 0, 1023, 0, 255); // Map the LDR value to LED brightness (0-255)
analogWrite(LED_PIN, brightness); // Set the LED brightness
Serial.print("LDR Value: ");
Serial.println(ldrValue);
delay(100); // Delay for smoother reading (adjust as needed)
}