Pulse wave modulation (widely known in power electronics as pulse width modulation, or PWM) is a digital switching technique that varies the on-time ratio (duty cycle) of a fixed-frequency square wave to control the average power delivered to a load without dropping the actual supply voltage.
In a real circuit, PWM changes the average voltage and power seen by the load over time, while the instantaneous voltage strictly alternates between zero and the full supply rail (e.g., 0V and 12V). People commonly confuse PWM with linear voltage regulation (like using an LM7805 or a potentiometer), which drops voltage by burning excess energy as heat, or with Pulse Frequency Modulation (PFM), which varies the switching speed rather than the on-time width.
The Core Concept: Average Power vs. Instantaneous Voltage
Think of a water valve connected to a hose. If you want half the water flow, you could either install a narrower pipe (linear regulation, which creates pressure drop and friction/heat) or you could rapidly snap the valve fully open and fully closed 100 times a second, leaving it open for exactly half the time (PWM). The water pressure in the pipe when open is always 100%, but the average volume delivered to the bucket is 50%.
Electrically, a microcontroller GPIO pin outputs a square wave. The duty cycle is the percentage of one period where the signal is HIGH. Because mechanical and thermal loads (like motors and incandescent bulbs) have inherent inertia or thermal mass, they cannot react to microsecond switching. They only respond to the mathematical average of the voltage.
Worked Numeric Example: Driving a 12V Fan at Half Speed
Let's say you want to run a 12V PC fan (like a Noctua NF-A12x25) at exactly 50% speed using a 3.3V logic signal from an ESP32. You cannot feed 3.3V directly into a 12V fan, and using a linear resistor would waste massive amounts of heat. Instead, you use the ESP32 to switch a logic-level MOSFET (like the IRLZ44N) that connects the fan to the 12V rail.
Here is the exact math and timing for the PWM signal:
- Target Frequency: 25,000 Hz (25 kHz). We choose this because it is above the upper limit of human hearing (20 kHz), eliminating audible coil whine from the fan motor.
- Period (T): 1 / 25,000 = 0.00004 seconds (40 µs).
- Target Duty Cycle: 50%.
- High Time (On): 40 µs * 0.50 = 20 µs at 12V (MOSFET conducting).
- Low Time (Off): 40 µs * 0.50 = 20 µs at 0V (MOSFET blocking).
- Average Voltage: 12V * 0.50 = 6V RMS equivalent delivered to the fan.
Where You Meet Pulse Wave Modulation in Practice
You will encounter PWM across almost every sub-discipline of electrical engineering and DIY making. Here is where it actually matters on the bench:
DC Motor Speed Control
Using H-bridge drivers like the TI DRV8871 or ST L298N, PWM dictates motor speed. Because motors are highly inductive loads, the collapsing magnetic field during the 'OFF' phase generates flyback voltage spikes. This is why PWM motor circuits mandate reverse-biased flyback diodes (like the 1N5819 Schottky) across the motor terminals to protect the switching MOSFETs.
LED Dimming and Display Backlights
Human eyes integrate light over time, making PWM ideal for LEDs. Unlike analog dimming (which shifts the LED's forward voltage and alters its color temperature), PWM keeps the LED driven at its exact rated forward current during the 'ON' pulses, preserving accurate color rendering while adjusting perceived brightness.
Switch-Mode Power Supplies (SMPS)
Buck and boost converters (like those built around the LM2596 or UC3842) use high-frequency PWM to control the energy transfer into an inductor. The controller dynamically adjusts the duty cycle on a cycle-by-cycle basis to maintain a rigid output voltage regardless of input sag or load spikes.
Decision Tree: Picking Your PWM Frequency and Driver
Choosing the wrong PWM frequency results in audible noise, excessive switching losses, or visible flicker. Use this decision matrix to select your parameters and specific driver components.
| If Your Load Is... | Target Frequency | Why This Frequency? | Concrete Driver / Part Pick |
|---|---|---|---|
| DC Motor (Brushed) | 1 kHz - 20 kHz | Low enough to minimize MOSFET switching heat; high enough to smooth out torque ripple. | TI DRV8871 (H-Bridge) or IRLZ44N (Uni-directional) |
| LED Strip (Analog) | 5 kHz - 10 kHz | Eliminates visible flicker on smartphone cameras and prevents eye strain. | TLC5940 (16-channel sink) or direct ESP32 GPIO |
| PC Cooling Fan (4-pin) | 25 kHz | Strictly required by Intel 4-wire fan specs to avoid audible acoustic noise. | MAX6639 (Fan controller) or NPN transistor circuit |
| SMPS / Buck Converter | 100 kHz - 2 MHz | Allows the use of physically smaller inductors and ceramic output capacitors. | LM2596 (150kHz) or TI TPS5430 (500kHz) |
| Audio Synth VCO | 20 Hz - 20 kHz (Audio Rate) | Sweeps through the audible spectrum to create harmonic timbre changes. | CEM3340 VCO chip or NE555 Timer astable circuit |
Frequently Asked Questions
Does PWM reduce the current draw from my power supply?
Yes, but it depends on the load type. For a resistive load (like a heating element), a 50% duty cycle draws exactly 50% of the average current from the supply. However, for a highly inductive load (like a DC motor), the inductor stores energy during the ON pulse and continues to circulate current through the flyback diode during the OFF pulse. The power supply still sees pulsed current spikes, which is why you must size your power supply and wiring for the peak current, not just the average.
Why does my ESP32 PWM output glitch when I use WiFi?
The ESP32's standard analogWrite() function uses software timers that can be interrupted by the WiFi and Bluetooth radio stacks, causing jitter in the duty cycle. To fix this, always use the ESP32's dedicated hardware LEDC (LED Control) peripheral. According to the official Espressif LEDC documentation, the hardware peripheral generates the square wave entirely in the background without CPU intervention, guaranteeing rock-solid timing even during heavy network traffic.
Can I use a standard NPN transistor (like a 2N2222) for PWM?
You can, but only for very low currents (under 500mA). Bipolar Junction Transistors (BJTs) are current-controlled devices and suffer from saturation voltage drops (Vce_sat) that waste power as heat. For anything above a few hundred milliamps, always use a logic-level MOSFET. MOSFETs are voltage-controlled, have near-zero on-resistance (Rds_on), and switch much faster, which is critical for maintaining clean square wave edges at high PWM frequencies. For a deeper look at the physics of switching losses, All About Circuits provides an excellent breakdown of why MOSFET gate charge matters in PWM design.






