Arduino PWM, Analog Inputs & Servo Control Explained
One of the most common surprises in beginner microcontroller work is that Arduino’s analogWrite() function does not output a smooth analog voltage. Instead, it switches a digital pin between 0 V and 5 V hundreds of times per second. Knowing how ADC input scaling, PWM duty cycle, and servo pulses differ unlocks almost every interactive sensor project.
Explore Learn Arduino & its website →
Numeric ranges apply to standard 10-bit ADC and 8-bit PWM timers on the Arduino Uno, matching NavSprout’s interactive Learn Arduino lessons.
Three different “analog” concepts on Arduino
Beginners often conflate analogRead(), analogWrite(), and Servo.write() because all three deal with continuous-looking physical quantities like knob angle, LED brightness, or motor position. Underneath, they use completely different electrical signals.
| Function | Signal type | Numeric range | What changes physically |
|---|---|---|---|
| analogRead(A0) | 10-bit ADC voltage measurement | 0 to 1023 | Maps 0 V – 5 V input into 1,024 discrete steps (~4.88 mV/step) |
| analogWrite(pin, v) | PWM square wave (~490 Hz or ~980 Hz) | 0 to 255 | Changes duty cycle from 0% to 100% on-time |
| servo.write(deg) | 50 Hz control pulse (20 ms period) | 0° to 180° | Changes pulse width between ~1.0 ms and ~2.0 ms |
Mapping a potentiometer cleanly to LEDs and servos
Because analogRead() spans 0–1023 while analogWrite() spans 0–255, passing a raw sensor value straight into analogWrite() wraps around four times across a single turn of the knob. Dividing by 4 (or using map(raw, 0, 1023, 0, 255)) keeps brightness monotonic from fully off to full brightness.
For a hobby servo, map(raw, 0, 1023, 0, 180) translates the full knob travel into the servo’s mechanical sweep. Always power larger servos from a dedicated 5 V supply with a shared ground rather than drawing stall current through the Arduino’s onboard regulator.
Practice all three signals in Learn Arduino
- Open the Knob lesson and sweep the potentiometer from 0% to 100% while watching the ADC count and voltage reading change together.
- Open the RGB LED lesson and adjust each channel’s PWM duty cycle to see how three digital pulse trains blend into smooth color.
- Open the Servo lesson and notice how the target angle maps to a narrow 1–2 ms control pulse repeated every 20 ms.
Common questions
Why does my LED look dimmer at 50% PWM than half as bright?
Human vision responds logarithmically to brightness, so a 50% duty cycle looks roughly 70–75% as bright. Gamma correction tables map linear slider steps to visually smooth dimming.
Which pins on an Arduino Uno support analogWrite()?
Pins 3, 5, 6, 9, 10, and 11 (marked with a ~ tilde on the board) are wired to hardware timers for PWM output.
Can I turn a PWM pin into a true analog voltage?
Yes, for low-current signals you can pass a PWM output through an RC low-pass filter (a resistor and capacitor) to smooth the pulses into an average DC voltage.
Sources & editorial method
Written by NavSprout Editorial. Published and checked .
Report a correction →