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.
- • Basic Voltage and Transistor switching
- • 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.
Duty Cycle Formula & Effective Average Voltage
The key metric of any PWM signal is its Duty Cycle (D):
Effective Average Voltage:
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)
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.
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°).
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.