Circuits / Microcontrollers
Arduino UNO: a potentiometer dims an LED (ADC and PWM)
analogRead turns a voltage into 0…1023; analogWrite turns 0…255 into the share of time the pin is high

Tap a part to see its voltages and currents. It is a model, not a measurement.
What do you need?
- Potentiometer 10 kΩSearch on Amazon
- Development board Arduino UNOSearch on Amazon
- Red LEDSearch on Amazon
- Resistor 220 ΩSearch on Amazon
- Jumper wires × 2Search on Amazon
- BreadboardSearch on Amazon
How does an Arduino dim an LED with a potentiometer?
Two conversions happen here. analogRead(A0) measures the voltage on the potentiometer's wiper, from 0 to 5 V, and turns it into a number from 0 to 1023, the 10 bits of the UNO's converter. With the knob at the middle, the wiper is at 2.5 V and the reading is about 512. analogWrite(9, reading / 4) then sets pin 9's PWM from 0 to 255: at 128 the pin is high half of the time, switching about 490 times per second. The LED does not receive a lower voltage. It gets full pulses of about 12 mA through R1 (220 Ω), and your eye averages them into half brightness. Dividing by 4 maps the 1024 readings onto the 256 PWM steps. The program also prints each reading to the serial monitor every 200 ms.
Values from the Protoboard ISO simulation: a model, not a bench measurement.
Hear about the next circuit
One email when a new circuit is out, about twice a month. Nothing else.