In modern electronics, controlling electrical devices accurately and efficiently is a major challenge. Engineers need methods to control motor speed, adjust LED brightness, generate audio signals, and manage power in electronic circuits.
One of the most widely used techniques for this purpose is Pulse Width Modulation (PWM).
PWM is a simple but powerful technology used in almost every field of electronics, including embedded systems, robotics, automation, power electronics, and IoT devices.
From controlling the speed of a small DC motor in a robot to adjusting the brightness of an LED display, PWM provides an efficient way to control electrical power without using complex analog circuits.
In this article, we will understand how PWM works and where it is used, including practical examples from Arduino, Raspberry Pi, and embedded systems.
Table of Contents
- What is PWM?
- How PWM Works
- Understanding PWM Signal
- What is Duty Cycle in PWM?
- PWM Frequency Explained
- Why Use PWM Instead of Analog Control?
- Practical Applications of PWM
- PWM in Embedded Systems
- Conclusion
What is PWM?
Pulse Width Modulation (PWM) is a technique used to control the average power delivered to an electrical device by rapidly switching a digital signal between ON and OFF states.
A PWM signal consists of:
- High state (ON) → Full voltage supplied
- Low state (OFF) → No voltage supplied
Instead of continuously changing the voltage level, PWM controls the amount of energy delivered by changing how long the signal stays ON.
For example, if a microcontroller operates at 5V:
- ON state = 5V
- OFF state = 0V
By switching between these two states very quickly, we can create an output that behaves like a variable voltage.
A simple example:
- 100% ON time → Full power
- 50% ON time → Half power
- 10% ON time → Low power
This ON-time percentage is called the duty cycle.
How PWM Works
To understand how PWM works and where it is used, we first need to understand its basic operation.A PWM signal is created by switching a digital output pin ON and OFF at a fixed frequency.The switching happens much faster than humans can notice.
For example:
A microcontroller output pin may switch thousands of times per second.When the signal remains ON for a longer period, more energy is delivered to the load.When the signal remains OFF for a longer period, less energy is delivered.The device receives a series of pulses, but because the switching is very fast, the output behaves like a controlled average voltage.
Example of PWM Operation
Imagine controlling an LED connected to a microcontroller.
Without PWM:
- HIGH → LED fully ON
- LOW → LED OFF
There are only two brightness levels.
With PWM:
- 100% duty cycle → Maximum brightness
- 50% duty cycle → Medium brightness
- 10% duty cycle → Very dim
The LED is still switching ON and OFF, but the human eye sees it as a continuous brightness level.
Understanding PWM Signal
A PWM waveform is a square wave signal with a fixed frequency.
It has three important parameters:
1. Pulse Width
Pulse width represents how long the signal stays HIGH during each cycle.A wider pulse means more power is delivered.A narrower pulse means less power is delivered.
2. Period
The period is the total time required for one complete PWM cycle.
One cycle includes:
- ON time
- OFF time
3. Frequency
Frequency represents how many PWM cycles occur in one second.
It is measured in Hertz (Hz).
For example:
- 100 Hz = 100 cycles per second
- 1 kHz = 1000 cycles per second
Higher frequency PWM provides smoother control for many applications.
What Is PWM Duty Cycle?
The most important concept in PWM is the duty cycle.Duty cycle represents the percentage of time the PWM signal remains ON during one cycle.It is calculated using:
Duty Cycle (%) = (ON Time / Total Time) × 100
For example:
If a PWM signal stays ON for half of the cycle:
Duty Cycle = 50%
This means the device receives approximately 50% of the available power.
Different Duty Cycle Examples
0% Duty Cycle
The signal is always OFF.
Output power = 0%
Example:
- Motor stopped
- LED completely OFF
50% Duty Cycle
The signal is ON for half of the cycle.
Output power ≈ 50%
Example:
- Medium LED brightness
- Medium motor speed
100% Duty Cycle
The signal is always ON.
Output power = Maximum
Example:
- Full motor speed
- Maximum LED brightness
PWM Frequency Explained
PWM frequency determines how fast the switching occurs.
Choosing the correct frequency is important because different applications require different frequencies.
Low Frequency PWM
Used for:
- Simple LED control
- Basic motor control
Example:
100 Hz PWM
However, very low frequencies can cause visible flickering in LEDs or vibration in motors.
High Frequency PWM
Used for:
- Motor controllers
- Audio systems
- Switching power supplies
Example:
20 kHz PWM
High-frequency PWM provides smoother operation and reduces unwanted noise.
Why Use PWM Instead of Analog Control?
A common question is:
Why not simply reduce voltage to control a device?
The answer is efficiency.
Traditional analog control wastes energy as heat.
For example, using a resistor to reduce motor speed converts extra energy into heat.
PWM works differently.
The switching device is either:
- Fully ON → Very low resistance
- Fully OFF → Almost no current flow
Because of this, very little energy is wasted.
Advantages of PWM:
✅ High efficiency
✅ Less heat generation
✅ Easy implementation using microcontrollers
✅ Accurate digital control
✅ Suitable for automation and robotics
PWM in Embedded Systems
PWM is extremely important in embedded systems because microcontrollers can easily generate PWM signals using built-in timers.
Popular platforms using PWM include:
- Arduino
- ESP32
- Raspberry Pi
- STM32 microcontrollers
- PIC microcontrollers
Most modern microcontrollers have dedicated PWM hardware modules that generate accurate signals without continuously using CPU resources.
Practical Example: PWM in Arduino
Arduino boards use PWM pins to control output devices.
Example applications:
- LED brightness control
- Motor speed control
- Servo motor control
A simple Arduino PWM command:
analogWrite(pin, value);The value usually ranges from:
- 0 → 0% duty cycle
- 255 → 100% duty cycle
Example:
analogWrite(9, 128);This produces approximately:
50% duty cycle output.
The LED connected to pin 9 will glow at half brightness.

