Electronics · Arduino
Arduino PWM calculator.
analogWrite takes 0 to 255. Convert that to duty cycle and average output voltage, or work backwards from the duty or voltage you want.
Inputs
Result
Enter a value.
analogWrite value, duty cycle and average voltage
Duty cycle = value ÷ 255, and average voltage = duty × logic voltage. The Arduino reference says the value is the duty cycle between 0 (always off) and 255 (always on). The pin is actually switching fully on and off, so the figure is an average, not a steady analog level.
Worked example. analogWrite(pin, 128) on a 5 V board: 128 ÷ 255 = 50.2% duty, an average of 2.51 V. For 25% duty the value is round(0.25 × 255) = 64. For an average of 2 V on a 3.3 V board the value is round(2 ÷ 3.3 × 255) = 155, which gives 2.01 V.
PWM frequency. From the Arduino reference: Uno R3, Nano and Mini 490 Hz (pins 5 and 6 at 980 Hz); Uno R4 490 Hz; Mega 490 Hz (pins 4 and 13 at 980 Hz); Leonardo and Micro 490 Hz (pins 3 and 11 at 980 Hz); Uno WiFi Rev2 and Nano Every 976 Hz; Zero, MKR and Nano 33 IoT 732 Hz; Due 1000 Hz. Only the pins marked PWM on your board work with analogWrite.
PWM suits dimming an LED or driving a transistor-switched load. It does not give a clean DC voltage unless you add an RC filter; use the RC time constant calculator to size one. Never drive a motor or other load directly from a pin; use a transistor or driver rated for it.
Frequently asked questions
What duty cycle is analogWrite(128)?
128 ÷ 255 = 50.2%, about half. On a 5 V board the average is 2.51 V.
What value gives 25% duty?
round(0.25 × 255) = 64. The exact duty is then 25.1% because the value must be a whole number.
What is the PWM frequency of an Arduino Uno?
The reference lists 490 Hz on pins 3, 9, 10 and 11 and 980 Hz on pins 5 and 6.
Is analogWrite a real analog voltage?
No. The pin switches between 0 V and the logic voltage; the figure here is the average over time. A multimeter, an LED or an RC filter averages it, a logic input does not.
Can I use analogWrite on any pin?
No, only the PWM pins listed for your board, for example 3, 5, 6, 9, 10 and 11 on an Uno.
Sources
Checked
- Arduino language reference source: analogWrite() (arduino/reference-en on GitHub)
- Wikipedia: RC time constant
Runs entirely in your browser. Nothing you type is sent or stored.
Scope and safety
Low-voltage hobby use only. These results are arithmetic from the formulas shown, not an engineering design or professional advice. Real parts vary with tolerance, temperature and age, so check the datasheet for every part. Never work on mains-powered circuits from a calculator result, and treat lithium and other rechargeable batteries with care. Frequencies are those listed for each board family in the Arduino reference; other cores and timers can change them.