Quick Reference

PWM Explained

Pulse Width Modulation for Motor Control

What is PWM?

PWM (Pulse Width Modulation) is a technique for controlling power by rapidly switching it on and off. The ratio of ON time to total time is called the duty cycle.

Duty Cycle Examples

0%
Always OFF
0V average
25%
ON 1/4 time
1.25V avg
50%
ON half time
2.5V avg
75%
ON 3/4 time
3.75V avg
100%
Always ON
5V average

Arduino PWM Pins

Pins marked with ~ symbol support PWM output:

3
5
6
9
10
11

Arduino Uno/Nano: Pins 3, 5, 6, 9, 10, 11
Arduino Mega: Pins 2-13, 44-46

analogWrite() Function

analogWrite(pin, value); // value: 0-255
  • 0
    0% Duty Cycle (OFF)
    Motor stopped, LED off
  • 127
    ~50% Duty Cycle
    Half speed motor, medium LED brightness
  • 255
    100% Duty Cycle (ON)
    Full speed motor, maximum LED brightness

Common Applications

  • 1
    Motor Speed Control
    Higher duty cycle = faster rotation speed
  • 2
    Servo Position Control
    Specific pulse widths = specific angles (1-2ms)
  • 3
    LED Brightness
    Variable duty cycle creates perceived dimming
  • 4
    Analog Voltage Simulation
    Create "analog" voltages using digital signals

PWM Frequency

Default Frequencies
Pins 3, 9, 10, 11: ~490 Hz
Pins 5, 6: ~980 Hz

Fast enough that motors and LEDs appear to operate smoothly without visible flicker.