// Define constants
const int potentiometerPin = A0; // Analog pin for potentiometer
const int ledPin = 9; // PWM pin for LED
void setup() {
pinMode(potentiometerPin, INPUT); // Set potentiometer pin as input
pinMode(ledPin, OUTPUT); // Set LED pin as output
}
void loop() {
// Read the value from the potentiometer (0 to 1023)
int potValue = analogRead(potentiometerPin);
// Map the potentiometer value to the range of the LED brightness (0 to 255)
int brightness = map(potValue, 0, 1023, 0, 255);
// Set the brightness of the LED
analogWrite(ledPin, brightness);
// Optional: You can add a delay if needed
// delay(10);
}