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
- 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.
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
- The period is T = 3 ms + 1 ms = 4 ms. The duty cycle is the fraction of each period spent HIGH.
- duty = 3 ms over 4 ms = 0.75 = 75%
Answer: 75%
Problem 2 of 10
A 5 V PWM signal has a 40% duty cycle. What is its average voltage?
Show the working
- Vavg = duty × Vhigh: it's at 5 V for 40% of each period and 0 V for the rest.
- Vavg = 0.4 × 5 V = 2 V
Answer: 2 V
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
- The period is T = 1 over f = 1 over 20,000 Hz = 0.00005 s = 50 µs.
- duty = 35 µs over 50 µs = 0.7 = 70%
Answer: 70%
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
- The period is T = 1 over 490 Hz ≈ 0.00204 s ≈ 2041 µs.
- ton = duty × T = 0.25 × 2041 µs ≈ 510 µs
Answer: 510 µs
Problem 5 of 10
analogWrite(10, 64) runs on an Arduino. What duty cycle does the pin give?
Show the working
- analogWrite takes 0 (always LOW) to 255 (always HIGH), so duty = value over 255.
- duty = 64 over 255 ≈ 0.251 = 25.1%
Answer: 25.1%
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
- Rearrange duty = value over 255: value = duty × 255.
- value = 0.6 × 255 = 153
Answer: 153
Problem 7 of 10
analogWrite(9, 179) runs on a 5 V Arduino. What is the pin's average voltage?
Show the working
- duty = 179 over 255 ≈ 0.702
- Vavg = 0.702 × 5 V ≈ 3.51 V
Answer: 3.51 V
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
- While it's on, P = V × I = 2 V × 20 mA = 40 mW. While it's off, it dissipates nothing.
- Pavg = duty × Pon = 0.3 × 40 mW = 12 mW
Answer: 12 mW
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
- duty = 200 over 255 ≈ 0.784
- T = 1 over 490 Hz ≈ 2.04 ms
- ton = 0.784 × 2.04 ms ≈ 1.6 ms
Answer: 1.6 ms
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
- While it's on, P = V² over R = 144 over 6 Ω = 24 W. While it's off, 0 W.
- Pavg = duty × Pon = 0.25 × 24 W = 6 W
- 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
“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.
“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 neededCheck 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
- Ohm's law practice problemsFind V, I or R, then the power, with the working for each.
- Units and prefixes practice problemsConvert mA, kΩ, µF, nF, pF, ms and mV, with the working for each.
- LED resistor practice problemsSize the resistor for one LED or a string, round to a standard value, check the power.
- Electrical power practice problemsPower three ways, energy in kWh, battery life and running costs, all worked.
- Series and parallel resistors practice problemsTotals in series and parallel, mixed networks and branch currents, all worked.
- Kirchhoff's laws practice problemsBalance currents at a junction and voltages round a loop, with the working for each.
- Voltage divider practice problemsFind Vout, pick R2 for a target and work out loading, with the working for each.
- Thevenin and Norton equivalent practice problemsReduce a network to V_th in series with R_th, then load it, with the working.
- Capacitor practice problemsCharge, capacitance, series and parallel, and stored energy, with the working.
- RC time constant practice problemsτ = R × C, the 63% rule, charging and discharging, with the working.
- Inductor practice problemsV = L × ΔI ÷ Δt, stored energy and inductors in series and parallel, with the working.
- RL circuit time constant practice problemsτ = L ÷ R, the current's rise and decay, and inductive kickback, with the working.
- AC voltage and transformer practice problemsPeak, RMS, period, AC power and transformer turns ratios, with the working.
- Capacitive and inductive reactance practice problemsCapacitive and inductive reactance, AC current and impedance, with the working.
- Impedance practice problems for RC and RL circuitsSeries RC and RL impedance, phase angle and current, with the working.
- RC filter practice problemsCutoff frequency, choosing R or C, and the output either side of the cutoff, with the working.
- Decibel practice problemsRatios to dB and back, for power and voltage, gains that add and the −3 dB point.
- LC resonance practice problemsf₀ = 1 ÷ (2π√(LC)), tuning for a frequency, and scaling, with the working.
- Diode practice problemsForward voltage, series resistor current, diodes in series, reverse bias and power dissipation.
- Rectifier and ripple practice problemsPeak output, ripple and the smoothing capacitor for half-wave and bridge rectifiers.
- Zener diode practice problemsSize a Zener regulator's resistor, split its current and check the Zener's power.
- Transistor switch practice problemsBase current, base resistor and load current for a BJT switch, then a MOSFET.
- MOSFET switch practice problemsConduction loss from R_DS(on), gate and pull-down currents, flyback diodes and junction temperature.
- Op-amp gain practice problemsInverting and non-inverting gain, the output, the resistor to pick and when it clips.
- Inverting and summing amplifier practice problemsInverting gain, input resistance, summing amps, averaging, a simple DAC and clipping.
- Schmitt trigger and hysteresis practice problemsHysteresis band, both thresholds and the feedback resistor for a comparator.
- Op-amp limits practice problemsGain-bandwidth, slew rate, output swing and input offset, with the working.
- Binary and hex practice problemsBinary to decimal and back, bits needed, the largest n-bit number and hex.
- Logic gates practice problemsGate outputs, truth-table rows, Boolean expressions and fewer gates, with the working.
- Counters and flip-flops practice problemsTop count, flip-flops needed, frequency division, rollover and ripple delay.
- ADC and analog input practice problemsanalogRead to volts and back, resolution, dividers and 12-bit ADCs, with the working.