const int potPin = A0; // Potentiometer connected to analog pin A0
const int ledPin = 9; // LED connected to digital pin 9
void setup() {
pinMode(ledPin, OUTPUT); // Set the LED pin as an output
Serial.begin(9600); // Initialize serial communication
}
void loop() {
int sensorValue = analogRead(potPin); // Read the potentiometer value (0-1023)
int brightness = map(sensorValue, 0, 1023, 0, 255); // Map the sensor value to LED brightness (0-255)
analogWrite(ledPin, brightness); // Set the LED brightness
Serial.print("Potentiometer Value: ");
Serial.print(sensorValue);
Serial.print(" | LED Brightness: ");
Serial.println(brightness);
delay(100); // Delay for stability
}