Tap the parts to see what each one does. A teaching simulation, not a circuit simulator.
Build it step by step
0 of 4 donePlace the potentiometer
Put the three pins in three separate rows.
Make the divider
One outer pin to 5V, the other to GND, the middle pin to A0.
Add the LED on a PWM pin
D9 to the 220 Ω resistor, resistor to the LED's long leg, short leg to GND.
Upload and turn the knob
Upload, open the serial monitor at 9600 baud and turn the knob end to end.
How do you build a PWM LED dimmer?
Turn a potentiometer to set an LED's brightness with PWM on an Arduino Uno. You need Arduino Uno R3, Potentiometer 10 kΩ, LED 5 mm red, Resistor 220 Ω and Breadboard 830 Tie Points. It takes 4 steps and about 40 minutes.
- Level
- Beginner
- Time
- About 40 min
- Parts
- 5
Parts list
- Development BoardsBuyArduino Uno R3 × 1
- PassivesBuy
- SemiconductorsBuyLED 5 mm red × 1
- PassivesBuyResistor 220 Ω × 1
- PrototypingBuy
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| Potentiometer outer pin | Uno 5V | Top of the divider |
| Potentiometer other outer pin | Uno GND | Bottom of the divider |
| Potentiometer wiper (middle) | Uno A0 | Analog input |
| Uno D9 (PWM ~) | 220 Ω resistor, then LED anode | PWM output |
| LED cathode | Uno GND | Return path |
Code
Arduino IDE, board "Arduino Uno". No extra libraries.
Runs on a virtual Arduino Uno in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).
const int POT_PIN = A0;
const int LED_PIN = 9; // a PWM pin (~)
void setup() {
pinMode(LED_PIN, OUTPUT);
Serial.begin(9600);
}
void loop() {
int raw = analogRead(POT_PIN); // 0 to 1023
int duty = map(raw, 0, 1023, 0, 255); // 0 to 255
analogWrite(LED_PIN, duty);
Serial.print("raw="); Serial.print(raw);
Serial.print(" duty="); Serial.println(duty);
delay(100);
}Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Knob fully one way | raw near 0, duty 0, LED off |
| Knob fully the other way | raw near 1023, duty 255, LED fully on |
| Knob in the middle | raw about 512, duty about 127, LED visibly dimmer |
| Measure D9 with a multimeter at mid position | About 2.5 V average (the meter averages the PWM) |
If it does not work
Brightness jumps or does not change
Check the LED is on a PWM pin marked ~ (3, 5, 6, 9, 10, 11).
raw stuck at 0 or 1023
The wiper is not on A0, or an outer pin is not connected.
Brightness changes backwards
Swap the two outer pins of the potentiometer.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the PWM LED dimmer?
Arduino Uno R3, Potentiometer 10 kΩ, LED 5 mm red, Resistor 220 Ω and Breadboard 830 Tie Points.
How long does the PWM LED dimmer take to build?
About 40 minutes for a beginner maker, in 4 steps.
How do I know the PWM LED dimmer works?
Knob fully one way: raw near 0, duty 0, LED off. Knob fully the other way: raw near 1023, duty 255, LED fully on. Knob in the middle: raw about 512, duty about 127, LED visibly dimmer.
Brightness jumps or does not change: what should I check?
Check the LED is on a PWM pin marked ~ (3, 5, 6, 9, 10, 11).
raw stuck at 0 or 1023: what should I check?
The wiper is not on A0, or an outer pin is not connected.
Brightness changes backwards: what should I check?
Swap the two outer pins of the potentiometer.
