PinoutSearch

Potentiometer-Dimmed LED (Arduino)

Turn a knob to smoothly control LED brightness. Learn analogRead, map(), and analogWrite.

Beginner15 min

What you need

Wiring

Hover a pin or a wire to trace the connection.

Code

pot_dimmer.ino
// Read a potentiometer and use it to dim an LED.
const int potPin = A0;
const int ledPin = 9;   // PWM pin (~)

void setup() {
  pinMode(ledPin, OUTPUT);
}

void loop() {
  int raw = analogRead(potPin);          // 0–1023
  int brightness = map(raw, 0, 1023, 0, 255);
  analogWrite(ledPin, brightness);
}

Steps

  1. Wire the pot: outer pins to 5V and GND, wiper (middle) to A0.
  2. Wire the LED from D9 through a 220Ω resistor; cathode to GND.
  3. Upload, then turn the knob to dim the LED.