Skip to content

Practice problems

PWM and duty cycle practice problems

Pulse-width modulation (PWM) dims an LED or slows a motor by switching it fully on and off rapidly at a fixed frequency. The fraction of each period it's on, the duty cycle, sets the average voltage. These ten problems find the duty cycle, the average voltage, how long each pulse lasts, the analogWrite value for a given duty cycle, and the average power a load dissipates. Type your answer to check it, and open the working whenever you want it.

The method

duty = ton over T = value over 255 (analogWrite)
  • Average voltage: Vavg = duty × Vhigh, so 50% of 5 V is 2.5 V
  • Period: T = 1 ÷ f, so the on-time (pulse width) is ton = duty × T
  • Average power: Pavg = duty × Pon, the power while fully on times the duty cycle

The problems

Type your answer and tap Check. Every one has the working, step by step.

  1. Problem 1 of 10

    A PWM signal is HIGH for 3 ms, then LOW for 1 ms, repeating. What is its duty cycle?

    Show the working
    1. The period is T = 3 ms + 1 ms = 4 ms. The duty cycle is the fraction of each period spent HIGH.
    2. duty = 3 ms over 4 ms = 0.75 = 75%

    Answer: 75%

  2. Problem 2 of 10

    A 5 V PWM signal has a 40% duty cycle. What is its average voltage?

    Show the working
    1. Vavg = duty × Vhigh: it's at 5 V for 40% of each period and 0 V for the rest.
    2. Vavg = 0.4 × 5 V = 2 V

    Answer: 2 V

  3. Problem 3 of 10

    A motor driver switches at 20 kHz. Each pulse is HIGH for 35 µs (the pulse width). What is the duty cycle?

    Show the working
    1. The period is T = 1 over f = 1 over 20,000 Hz = 0.00005 s = 50 µs.
    2. duty = 35 µs over 50 µs = 0.7 = 70%

    Answer: 70%

  4. Problem 4 of 10

    An Arduino PWM pin runs at 490 Hz. At a 25% duty cycle, what is the on-time (how long the pin is HIGH in each period), in microseconds?

    Show the working
    1. The period is T = 1 over 490 Hz ≈ 0.00204 s ≈ 2041 µs.
    2. ton = duty × T = 0.25 × 2041 µs ≈ 510 µs

    Answer: 510 µs

  5. Problem 5 of 10

    analogWrite(10, 64) runs on an Arduino. What duty cycle does the pin give?

    Show the working
    1. analogWrite takes 0 (always LOW) to 255 (always HIGH), so duty = value over 255.
    2. duty = 64 over 255 ≈ 0.251 = 25.1%

    Answer: 25.1%

  6. Problem 6 of 10

    What value should analogWrite get for a 60% duty cycle? Type a whole number from 0 to 255.

    Show the working
    1. Rearrange duty = value over 255: value = duty × 255.
    2. value = 0.6 × 255 = 153

    Answer: 153

  7. Problem 7 of 10

    analogWrite(9, 179) runs on a 5 V Arduino. What is the pin's average voltage?

    Show the working
    1. duty = 179 over 255 ≈ 0.702
    2. Vavg = 0.702 × 5 V ≈ 3.51 V

    Answer: 3.51 V

  8. Problem 8 of 10

    A red LED has a forward voltage of 2 V and a forward current of 20 mA while its PWM pin is HIGH. At a 30% duty cycle, what is its average power, in milliwatts?

    Show the working
    1. While it's on, P = V × I = 2 V × 20 mA = 40 mW. While it's off, it dissipates nothing.
    2. Pavg = duty × Pon = 0.3 × 40 mW = 12 mW

    Answer: 12 mW

  9. Problem 9 of 10

    Stretch: analogWrite(9, 200) runs on an Arduino Uno, whose pin 9 outputs PWM at 490 Hz. What is the on-time in each period, in milliseconds?

    Show the working
    1. duty = 200 over 255 ≈ 0.784
    2. T = 1 over 490 Hz ≈ 2.04 ms
    3. ton = 0.784 × 2.04 ms ≈ 1.6 ms

    Answer: 1.6 ms

  10. Problem 10 of 10

    Stretch: a 12 V lamp with a 6 Ω filament runs from 12 V PWM at a 25% duty cycle. Take its resistance as constant. What average power does it dissipate?

    Show the working
    1. While it's on, P = V² over R = 144 over 6 Ω = 24 W. While it's off, 0 W.
    2. Pavg = duty × Pon = 0.25 × 24 W = 6 W
    3. Not 3² over 6 = 1.5 W: square the full 12 V, then multiply by the duty cycle, never the other way round. The answer is 6 W.

    Answer: 6 W

Build it in a free lesson

“Dimming with PWM” is lesson 5 of 6 in The Core, Electronics World 8. Free with an account. Lessons unlock in order, so you’ll do the 53 before it first.

Free lesson

Now build it yourself

Each lesson comes in three short parts: see the idea, try it on a live board, then build it yourself, with quick checks as you go.

Try it yourself: free lesson

“Dimming with PWM” is lesson 5 of 6 in The Core, Electronics World 8. Free with an account. Lessons unlock in order, so you’ll do the 53 before it first.

Or start from the very first lesson, no account needed

Check it with a calculator

The ideas behind it

Questions people ask

How do I work out duty cycle?

Divide the on-time (time HIGH) by the period, HIGH time plus LOW time, and multiply by 100 for a percentage. HIGH for 1 ms out of every 4 ms is 25% duty. The average voltage is then duty × the HIGH voltage.

What duty cycle does analogWrite give?

analogWrite(pin, value) takes 0 to 255, not a percentage: 0 is always LOW and 255 always HIGH. The duty cycle is value ÷ 255, so 128 gives about 50% and 64 about 25%. For p percent, the value is p × 255 ÷ 100.

Is PWM power the same as a steady average voltage?

No. A resistive load gets the full voltage while the pin is HIGH and nothing while it's LOW, so its average power is duty cycle × the full-on power. For a 6 Ω load on 12 V at 25%, that's 6 W, four times what a steady 3 V would give.

More practice