Lesson 4 of 16 · 15 min
Arduino Potentiometer: Read a Knob and Dim an LED
A potentiometer is a three-terminal variable resistor used as a voltage divider: on an Arduino, the outer legs go to 5 V and GND, the middle leg (wiper) goes to an analog pin, and analogRead() returns 0 at one end and 1023 at the other.
This lesson also runs on an interactive 3D board: wire it, press Run and watch the circuit respond.
Open the 3D lessonA potentiometer is a resistor with a wiper that slides along it. Wire the two ends to 5 V and ground and the wiper becomes a voltage between them — a knob that outputs 0 to 5 V. The Uno’s 10-bit ADC turns that into a whole number from 0 to 1023.
That number is the input side of a huge number of projects: volume controls, LED brightness, motor speed, threshold dials. Lesson 4 pairs it with PWM so the knob dims an LED, which is the smallest complete input-to-output loop you can build.
What you need
| Part | Qty | Notes |
|---|---|---|
| Arduino Uno R3 | 1 | A0 reads the knob, pin 9 drives the LED |
| 10 kΩ potentiometer | 1 | Linear taper, 3 legs, 270° travel |
| 220 Ω resistor + LED | 1 | The dimmable output |
| Breadboard + 5 jumpers | 1 | The pot needs both power rails |
How to wire it
Pot left leg → 5 V, right leg → GND, middle (wiper) → A0. Pin 9 → 220 Ω → LED → GND. Turning the knob moves the wiper voltage from 0 V to 5 V, and the reading follows from 0 to 1023.
| Pin | Connects to | What it does |
|---|---|---|
| 5V | Pot (left) | Top of the voltage divider. |
| A0 | Pot (middle) | The wiper: 0–5 V as you turn. |
| GND | Pot (right) | Bottom of the divider. |
| ~D9 | 220 Ω → LED | PWM output sets the brightness. |
Reading an Arduino potentiometer with analogRead()
The Uno's ADC is a 10-bit successive-approximation converter. One conversion takes about 100 µs and returns 0–1023, so each step is 5 V ÷ 1024 ≈ 4.9 mV. The converter wants a source impedance below roughly 10 kΩ for accurate readings, which is exactly why a 10 kΩ potentiometer is the default choice and a 100 kΩ one feels noisy.
The wiper is the output, not a supply. The two outer legs go to 5 V and GND, the middle leg goes to A0, and turning the shaft moves that middle leg between the two rails. If the reading never changes, the wiper is almost certainly wired to a rail instead of to the analog pin.
Mapping the knob to something useful
analogRead() gives 0–1023, analogWrite() wants 0–255, a servo wants 0–180. map() converts between them in one line, and constrain() keeps a noisy reading from producing a value outside the range — a servo commanded to 190° will grind against its end stop.
Raw readings jitter by a count or two, which is invisible on an LED and obvious on a servo. Average the last five readings, or add a dead band so the output only moves once the input has moved by more than four counts. For an LED, apply a gamma curve first: a linear duty cycle does not look linear to the eye.
Taper matters if the knob is meant to feel like a volume control. The letter stamped on the body tells you which one you have: B is linear, A is logarithmic. A logarithmic pot makes a dimmer feel wrong and a volume control feel right, and no amount of code turns one into the other convincingly.
The sketch
const int POT = A0; // wiper of the potentiometer
const int LED = 9; // PWM pin
void setup() {
Serial.begin(9600);
pinMode(LED, OUTPUT);
}
void loop() {
int value = analogRead(POT); // 0 at one end, 1023 at the other
int brightness = value / 4; // 0-255, what analogWrite wants
analogWrite(LED, brightness);
Serial.println(value); // watch it in the serial monitor
delay(50);
}
What the code does
- analogRead(POT) takes about 100 µs and returns 0–1023; 5 V ÷ 1024 gives roughly 4.9 mV per step.
- analogWrite only accepts 0–255, so value / 4 scales the bigger range down to fit.
- Serial.println(value) lets you watch the raw numbers in the serial monitor while you turn.
- delay(50) keeps the serial output readable; the LED update does not need it.
Specifications
| Item | Value |
|---|---|
| Potentiometer | 10 kΩ linear, 270° travel |
| ADC | 10-bit, 0–1023 |
| Resolution | ≈ 4.9 mV per step |
| PWM | 8-bit, 0–255 at ~490 Hz |
| Read time | ≈ 100 µs per analogRead() |
Common mistakes
- Wiring the wiper to 5 V and one end to the analog pin. The reading then never changes — the wiper is the output, not a supply.
- Expecting analogWrite() to work on every pin. Only 3, 5, 6, 9, 10 and 11 do PWM; on other pins it behaves like digitalWrite.
- Forgetting that the value is 0–1023, not 0–255. Writing analogWrite(LED, value) makes the LED sit at full brightness for most of the turn.
Sources
The figures in this lesson come from these documents. Every value in the tables above can be checked against them.
- analogRead() — Arduino language reference
- Analog inputs — how the Uno's ADC works
- analogWrite() — Arduino language reference
Frequently asked questions
Why does analogRead() return 0–1023 and not 0–255?
The Uno’s ADC is 10-bit: 2¹⁰ = 1024 steps. PWM output is 8-bit, 2⁸ = 256 steps, so divide by 4 (or use map()) before analogWrite().
Can I use a 100 kΩ potentiometer instead of 10 kΩ?
Yes, but a high value makes the ADC input more sensitive to noise and the reading jitters. 10 kΩ is the sweet spot for a 10-bit ADC; anything from 1 kΩ to 50 kΩ behaves well.
Why is my potentiometer reading jumpy?
Usually a loose wiper contact on a cheap pot, or long unshielded wires. Add a 100 nF capacitor from the wiper to ground, or average ten readings in software.
How do I make the LED respond evenly to the knob?
The eye perceives brightness roughly logarithmically, so a linear 0–255 ramp looks like it jumps at the top. Map the reading through a gamma curve, or use a value squared, for a smoother fade.
Want to see this circuit before you own the parts? The Arduino simulator draws this exact pin table on a 3D Uno R3: click any jumper to see what it carries, press Run and read the serial monitor.
Open the Arduino simulatorPublished 12 November 2026 · last updated 17 November 2026 · written and tested by Nick Hu.