

Pulse Width Modulation (PWM) is a technique used to control the amount of power delivered to an electrical load by varying the width of the pulses in a pulse train. By adjusting the duty cycle (the percentage of time the signal is "on" versus "off"), PWM enables precise control over power delivery without significant energy loss.
PWM is widely used in various applications, including:
PWM is not a physical component but rather a method implemented in microcontrollers, integrated circuits, or dedicated PWM controllers.








PWM signals are characterized by the following parameters:
The Arduino UNO microcontroller has several pins capable of generating PWM signals. These pins are marked with a ~ symbol on the board.
| Pin | PWM Channel | Timer Used | Notes |
|---|---|---|---|
| 3 | PWM Channel 1 | Timer 2 | Shared with Pin 11 |
| 5 | PWM Channel 2 | Timer 0 | Shared with Pin 6 |
| 6 | PWM Channel 3 | Timer 0 | Shared with Pin 5 |
| 9 | PWM Channel 4 | Timer 1 | Shared with Pin 10 |
| 10 | PWM Channel 5 | Timer 1 | Shared with Pin 9 |
| 11 | PWM Channel 6 | Timer 2 | Shared with Pin 3 |
The following example demonstrates how to use PWM to control the brightness of an LED connected to Pin 9 of an Arduino UNO.
// PWM Example: LED Brightness Control
// Connect an LED to Pin 9 with a current-limiting resistor (e.g., 220 ohms).
int pwmPin = 9; // PWM-capable pin
int brightness = 0; // Initial brightness (0-255)
int fadeAmount = 5; // Amount to change brightness
void setup() {
pinMode(pwmPin, OUTPUT); // Set the pin as an output
}
void loop() {
analogWrite(pwmPin, brightness); // Write PWM signal to the pin
// Change the brightness for the next loop
brightness = brightness + fadeAmount;
// Reverse the direction of fading at the ends of the range
if (brightness <= 0 || brightness >= 255) {
fadeAmount = -fadeAmount;
}
delay(30); // Pause to see the fading effect
}
Load Not Responding to PWM Signal
PWM Signal Causes Audible Noise
LED Flickering
Motor Jerking or Stalling
Q: Can I use PWM to generate an analog voltage?
A: Yes, by passing the PWM signal through a low-pass filter, you can approximate an analog voltage.
Q: What is the maximum resolution of PWM on an Arduino UNO?
A: The Arduino UNO typically supports 8-bit PWM resolution, allowing 256 discrete duty cycle levels (0-255).
Q: Can I use PWM to control AC devices?
A: PWM is primarily designed for DC loads. To control AC devices, you would need additional circuitry, such as a triac-based dimmer or an inverter.
Q: How do I calculate the duty cycle?
A: Duty cycle (%) = (Time ON / Total Period) × 100. For example, if the signal is ON for 2 ms in a 10 ms period, the duty cycle is 20%.
By following this documentation, you can effectively implement PWM in your projects for precise power control and signal modulation.