const int ldrPin = A0; // LDR connected to analog pin A0
const int ledPin = 9; // LED connected to digital pin 9
void setup() {
pinMode(ledPin, OUTPUT); // Set up the LED pin as an output
Serial.begin(9600); // Start serial communication at 9600 bps
}
void loop() {
int ldrValue = analogRead(ldrPin); // Read the LDR value
int ledBrightness = map(ldrValue, 0, 1023, 255, 0); // Map LDR value to LED brightness (inverted)
ledBrightness = constrain(ledBrightness, 0, 255); // Constrain the brightness to 0-255
analogWrite(ledPin, ledBrightness); // Set the LED brightness
Serial.println(ledBrightness); // Print the brightness value to serial monitor
delay(100); // Wait for 100 milliseconds
}