ohmio

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

Arduino UNO: a potentiometer dims an LED (ADC and PWM), simulated on a breadboard

Tap a part to see its voltages and currents. It is a model, not a measurement.

What do you need?

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.