Productive Toolbox

PWM Duty Cycle Calculator

Calculate PWM duty cycle, frequency, period, ON/OFF time instantly. Essential for motor control, LED dimming, Arduino projects, and signal processing applications.

PWM Duty Cycle Calculator

Calculate PWM duty cycle, frequency, period, ON/OFF time instantly. Essential for motor control, LED dimming, and signal processing.

Actions

Calculation Mode

Time Parameters

ms
ms

Common PWM Configurations

What is PWM (Pulse Width Modulation)?

PWM (Pulse Width Modulation) is a technique used to control the average power delivered to a load by switching it on and off at a high frequency. The duty cycle represents the percentage of time the signal is ON (high) versus the total period. PWM is widely used in motor speed control, LED brightness control, power regulation, audio synthesis, and digital-to-analog conversion. By varying the duty cycle, you can control the effective voltage or power delivered to the load without using variable resistors or linear regulators, making it highly efficient.

PWM Calculation Formulas

Duty Cycle Calculation

Duty Cycle (%) = (ON Time / Period) × 100

Where Period = ON Time + OFF Time. Duty cycle represents the fraction of time the signal is high. A 50% duty cycle means the signal is ON for half the period and OFF for the other half.

ON Time Calculation

ON Time = (Duty Cycle / 100) × Period

Calculate the ON time when you know the desired duty cycle and period. For example, a 25% duty cycle with 10ms period gives ON time = 0.25 × 10ms = 2.5ms.

Frequency and Period

Frequency (Hz) = 1 / Period (s)

Frequency is the number of complete cycles per second. A 1kHz PWM signal has a period of 1ms. Higher frequencies result in smoother control but may increase switching losses.

Complete Example

Given: ON Time = 2ms, OFF Time = 8ms

Step 1: Period = 2ms + 8ms = 10ms

Step 2: Duty Cycle = (2ms / 10ms) × 100 = 20%

Step 3: Frequency = 1 / 0.01s = 100 Hz

Common PWM Applications

Motor Speed Control: PWM controls DC motor speed by varying the average voltage. Higher duty cycle = faster speed. Typical frequency: 1-20kHz. Used in robotics, drones, electric vehicles, and industrial automation. Avoids heat dissipation of linear control methods.
LED Dimming: Control LED brightness without changing current. Duty cycle directly controls perceived brightness. Frequency > 100Hz avoids visible flicker. Used in displays, automotive lighting, and smart home systems. More efficient than resistive dimming.
Power Regulation: Switch-mode power supplies use PWM to regulate output voltage efficiently. Buck converters, boost converters, and DC-DC converters all rely on PWM. Efficiency > 90% compared to 50-60% for linear regulators.
Servo Control: Standard servos use 50Hz PWM with 1-2ms pulse width to control position. 1ms = 0°, 1.5ms = 90°, 2ms = 180°. Used in robotics, RC vehicles, and automation.
Audio Synthesis: Class-D amplifiers use PWM to generate audio signals with high efficiency. PWM frequency typically 200-500kHz, well above audible range. Used in portable speakers and automotive audio systems.

Arduino PWM Pins and Frequencies

BoardPWM PinsFrequencyResolution
Arduino Uno3, 5, 6, 9, 10, 11490 Hz (980 Hz on 5,6)8-bit (0-255)
Arduino Mega2-13, 44-46490 Hz (980 Hz on 4,13)8-bit (0-255)
ESP32All GPIO pins5 kHz (configurable)8-16 bit
Raspberry Pi PicoAll GPIO pins1 kHz (configurable)16-bit

Choosing PWM Frequency

Low Frequency (50-500 Hz): Used for servo control, heating elements, and applications where switching losses must be minimized. Visible flicker in LEDs. Lower EMI. Suitable for high-power applications with slow response time requirements.
Medium Frequency (1-20 kHz): Most common range for motor control and LED dimming. Above human hearing range (20 kHz) to avoid audible noise. Good balance between switching losses and control smoothness. Arduino default: 490-980 Hz.
High Frequency (20-500 kHz): Used in switch-mode power supplies, Class-D amplifiers, and applications requiring smooth output. Allows smaller filter components. Higher switching losses. Requires fast switching devices (MOSFETs, IGBTs).

PWM Resolution and Duty Cycle

Understanding Resolution

8-bit PWM (Arduino): 256 steps (0-255). Duty cycle = (value / 255) × 100%. Value 128 = 50% duty cycle. Sufficient for most applications.

10-bit PWM: 1024 steps (0-1023). Finer control, useful for precise motor speed or LED brightness control. Value 512 = 50% duty cycle.

16-bit PWM (ESP32, Pico): 65536 steps (0-65535). Ultra-fine control for professional applications. Value 32768 = 50% duty cycle.

Duty Cycle8-bit Value10-bit ValueApplication
0%00OFF / Stop
25%64256Low speed / Dim
50%128512Medium speed / Half brightness
75%192768High speed / Bright
100%2551023Full speed / Maximum brightness

Frequently Asked Questions

What is the difference between duty cycle and frequency?

Duty cycle is the percentage of time the signal is ON during one period, while frequency is the number of complete cycles per second. A 50% duty cycle at 1kHz means the signal is ON for 0.5ms and OFF for 0.5ms, repeating 1000 times per second. You can have the same duty cycle at different frequencies.

How do I calculate PWM duty cycle for Arduino?

Arduino uses 8-bit PWM (0-255). To set a specific duty cycle, use: analogWrite(pin, (dutyCycle / 100) × 255). For 50% duty cycle: analogWrite(9, 128). For 25%: analogWrite(9, 64). For 75%: analogWrite(9, 192). The default Arduino PWM frequency is 490 Hz on most pins.

What PWM frequency should I use for LED dimming?

Use at least 100 Hz to avoid visible flicker, but 200-1000 Hz is recommended for smooth dimming. Higher frequencies (1-10 kHz) eliminate flicker completely and work better with cameras. Very high frequencies (> 20 kHz) may cause audible noise in some LED drivers. Arduino default 490 Hz works well for most LED applications.

Can I use PWM to control AC devices?

Not directly. PWM from microcontrollers is DC (0-5V). To control AC devices, use a solid-state relay (SSR), TRIAC, or optocoupler with zero-crossing detection. For AC motor speed control, use phase control (dimmer circuit) or variable frequency drive (VFD), not simple PWM. Never connect PWM output directly to AC mains.

Why does my motor make noise with PWM control?

Audible noise occurs when PWM frequency is below 20 kHz (human hearing range). The motor vibrates at the PWM frequency, creating sound. Solution: Increase PWM frequency to 20-40 kHz using timer configuration. Trade-off: Higher frequency increases switching losses and heat in the motor driver. Use proper motor driver ICs designed for PWM control.

How do I convert PWM to analog voltage?

Use a low-pass RC filter. Connect PWM output to a resistor (1-10kΩ), then to a capacitor (0.1-10µF) to ground. Output voltage = Supply Voltage × (Duty Cycle / 100). For 5V PWM at 50% duty cycle, output is 2.5V. Filter cutoff frequency should be 10-100× lower than PWM frequency for smooth DC output. Add op-amp buffer for low-impedance output.

What is the maximum PWM frequency for Arduino?

Arduino Uno can achieve up to 62.5 kHz PWM by modifying timer prescaler, but at reduced resolution (4-bit instead of 8-bit). Default is 490 Hz (8-bit). ESP32 supports up to 40 MHz PWM with configurable resolution. Higher frequency requires lower resolution due to timer limitations. For most applications, 1-20 kHz at 8-bit resolution is optimal.

💡 Pro Tip

When using PWM for motor control, always use a motor driver IC (L298N, L293D, TB6612) instead of driving the motor directly from microcontroller pins. Motor drivers provide current amplification, flyback diode protection, and thermal shutdown. For LED dimming, use PWM frequency > 200 Hz to avoid flicker. For servo control, use exactly 50 Hz (20ms period) with 1-2ms pulse width. Always measure actual PWM frequency with an oscilloscope when precision matters, as software delays and interrupts can affect timing.