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.
Arduino PWM Pins
Pins marked with ~ symbol support PWM output:
Arduino Uno/Nano: Pins 3, 5, 6, 9, 10, 11
Arduino Mega: Pins 2-13, 44-46
analogWrite() Function
analogWrite(pin, value);
-
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.