← Back to Electronics

Calculator

Common supply voltages:
V
%
50%
For period / RC filter calc

Arduino analogWrite() reference

Arduino's analogWrite(pin, value) takes a value 0–255 (8-bit). The table below shows the mapping to duty cycle and average voltage for common Vcc values.

analogWrite value Duty cycle Avg @ 5 V Avg @ 3.3 V Common use

PWM basics

Formula

Vavg = Vcc × (DC / 100)
DC = (Vavg / Vcc) × 100

tH = T × DC / 100
tL = T × (1 − DC/100)
T = 1 / f

Smoothing PWM to DC

  • Use an RC low-pass filter with fc ≪ PWM frequency
  • Rule of thumb: fc = PWM freq / 10 to 100
  • Higher ratio → less ripple, slower response
  • For high current output, add an op-amp buffer after the RC filter
  • For DAC replacement: use R = 10 kΩ, calculate C from fc

Common applications

  • LED dimming — 100 Hz+ is flicker-free to the eye
  • Motor speed control — 1–20 kHz typical (above audible range)
  • Servo control — 50 Hz, 1–2 ms pulse width
  • DAC substitute — RC filter + buffer for analog output
  • Voltage regulation — buck/boost converter core principle

Arduino PWM pins

  • Uno / Nano: pins 3, 5, 6, 9, 10, 11 — 490 Hz (5, 6: 980 Hz)
  • Mega: pins 2–13, 44–46 — 490 Hz
  • ESP32: any GPIO, configurable freq + resolution
  • Resolution: 8-bit (0–255) on AVR, up to 16-bit on ESP32
  • Use analogWrite(pin, 0) for 0% and analogWrite(pin, 255) for 100%