MyRoboPathOpen Robotics Lab
electronics16 min readUpdated 2026-03-14Beginner

Introduction to PWM (Pulse Width Modulation): Duty Cycle & Motor Speed

Control power digitally: master Pulse Width Modulation (PWM), calculate duty cycle percentages, understand switching frequencies, dim LEDs smoothly, and control DC motor speed and servo angles.

MyRoboPath Engineering Lab
Peer-Reviewed Open-Source Hardware & Firmware Guide

Key Engineering Takeaways

  • •Pulse Width Modulation (PWM) rapidly toggles a digital signal between full ON and full OFF to simulate a variable analog voltage.
  • •Duty Cycle is the percentage of time the signal is ON during one full period: Duty Cycle (%) = (T_on / T_total) × 100.
  • •Average Voltage: V_avg = V_peak × Duty Cycle. At 50% duty cycle on 12V, V_avg = 6.0V.
  • •PWM is highly efficient because driving transistors operate strictly in Saturation (fully ON) or Cutoff (fully OFF), minimizing heat loss.
  • •For DC motors, use PWM frequencies above 20kHz to eliminate annoying audible coil whine.
Prerequisites
  • • Basic Voltage and Transistor switching
Required Hardware / Tools
  • • ESP32 / Arduino
  • • N-MOSFET Driver Module
  • • 12V DC Motor / LED Strip
  • • Oscilloscope (optional)

What is Pulse Width Modulation (PWM)?

Microcontrollers are purely digital devices: their output pins can only produce full HIGH (+3.3V / +5V) or full LOW (0V). They cannot directly output an analog +2.1V to run a motor at half speed.

Pulse Width Modulation (PWM) solves this limitation by switching the digital pin ON and OFF at high frequency (hundreds to thousands of times per second).

By varying the width of the ON pulse relative to the total period, we control the average electrical power delivered to the load.

PWM duty cycle waveform comparison
Figure 6.1: Pulse Width Modulation square waveforms at 25%, 50%, and 75% duty cycle.Visual Guide

Duty Cycle Formula & Effective Average Voltage

The key metric of any PWM signal is its Duty Cycle (D):

ΣFormula
Duty Cycle (D) = T_ON{T_ON + T_OFF} × 100%

Effective Average Voltage:

ΣFormula
V_average = V_supply × (Duty Cycle / 100)

Examples with a 12V Motor Supply:

  • 0% Duty Cycle: T_ON = 0ms → V_avg = 0.0V (Motor Stopped)
  • 25% Duty Cycle: V_avg = 12V × 0.25 = 3.0V (Slow Speed)
  • 50% Duty Cycle: V_avg = 12V × 0.50 = 6.0V (Half Speed)
  • 100% Duty Cycle: V_avg = 12.0V (Full Speed)
PWM average voltage calculation graph
Figure 6.2: Mathematical relationship between PWM pulse width and equivalent average output voltage.Visual Guide

Why PWM is 95%+ Efficient (Switching vs Linear Resistors)

Why not just use a variable resistor (potentiometer) to slow down a motor?

  • Linear Resistance: If you drop 12V to 6V across a series resistor running a 2A motor, the resistor dissipates P = 6V × 2A = 12 Watts of boiling wasted heat! (50% efficiency).
  • PWM Switching: A MOSFET switch is either fully ON (V_drop ≈ 0.05V → P ≈ 0.1W) or fully OFF (I = 0 to P = 0W). PWM achieves >95% energy efficiency, keeping batteries lasting hours without massive heat sinks.
Switching EfficiencyPWM switching delivers maximum torque at low speeds because the motor receives full-voltage kicks during every ON pulse.

Choosing PWM Frequencies for Motors, LEDs & Audio

Frequency Selection Guide:

  • LED Dimming (100Hz - 1kHz): Human eyes perceive anything above 100Hz as solid, flicker-free light.
  • DC Brushed Motors (20kHz - 25kHz): Low frequencies (1kHz) cause the motor iron core to vibrate, emitting an irritating high-pitched acoustic squeal. Frequencies >20kHz are above the human hearing range (silent operation).
  • RC Servos (50Hz): Standard positional hobby servos expect a fixed 50Hz (20ms period) control pulse where pulse width (1.0ms - 2.0ms) maps directly to angle (-90° to +90°).
RC servo 50Hz pulse timing diagram
Figure 6.3: RC servo 50Hz control pulse timing: 1.0ms (0°), 1.5ms (90°), and 2.0ms (180°).Visual Guide

Frequently Asked Questions

What is PWM resolution (8-bit vs 10-bit vs 16-bit)?

PWM resolution defines the number of discrete steps between 0% and 100% duty cycle: 8-bit resolution provides 256 steps (0-255), 10-bit provides 1024 steps (0-1023), and 16-bit provides 65,536 ultra-fine control steps.

Tags:#PWM#Pulse Width Modulation#Motor Speed Control#Duty Cycle#LED Dimming#Servos