📘 Lesson F9 – PWM (Pulse Width Modulation) and Signal Basics
🎯 Learning Objectives
After completing this lesson, students will be able to:
✅ Understand what PWM is
✅ Understand why PWM is needed
✅ Identify PWM pins on Arduino UNO
✅ Understand Duty Cycle
✅ Understand Frequency
✅ Control LED brightness using PWM
✅ Control motor speed using PWM
✅ Understand the difference between Digital Output and PWM Output
✅ Use PWM in real-world projects
1. Introduction
In previous lessons, we learned that digital pins can generate only two states:
HIGH (5V)
or
LOW (0V)
But many electronic devices require something between ON and OFF.
Examples:
- LED Brightness Control
- Motor Speed Control
- Fan Speed Control
- Servo Signal Generation
- Light Dimming Systems
Now the question is:
How can Arduino generate intermediate values if digital pins only understand HIGH and LOW?
The answer is:
PWM (Pulse Width Modulation)
2. What is PWM?
PWM stands for:
Pulse Width Modulation
PWM is a technique used to simulate analog output using digital signals.
Instead of producing a constant voltage, Arduino rapidly switches a pin:
ON
↓
OFF
↓
ON
↓
OFF
↓
ON
↓
OFF
thousands of times every second.
Because switching happens very fast, electronic devices behave as if they are receiving a lower voltage.
3. Understanding PWM with a Fan Example
Imagine a table fan.
Method 1
Power OFF
Fan Stops
Method 2
Power ON
Fan Runs Full Speed
But in real life we have:
- Speed 1
- Speed 2
- Speed 3
- Speed 4
PWM allows Arduino to achieve similar speed control.
4. Why PWM is Needed
Without PWM:
Digital Pins can only provide:
OFF
or
ON
With PWM:
Arduino can simulate:
- 10% Power
- 20% Power
- 50% Power
- 75% Power
- 100% Power
This makes smooth control possible.
5. PWM Pins on Arduino UNO
Not all digital pins support PWM.
Arduino UNO PWM Pins are:
| PWM Pin |
|---|
| D3 |
| D5 |
| D6 |
| D9 |
| D10 |
| D11 |
These pins are marked with:
~
symbol on the board.
6. How PWM Works
Consider a digital signal:
HIGH HIGH HIGH HIGH HIGH
Output:
100% Power
Now consider:
HIGH LOW HIGH LOW HIGH LOW
Output:
50% Power
Now consider:
HIGH LOW LOW LOW HIGH LOW LOW LOW
Output:
25% Power
The percentage of ON time determines output power.
This percentage is called:
Duty Cycle
7. What is Duty Cycle?
Duty Cycle represents:
Percentage of ON Time
during one PWM cycle.
Formula
Duty Cycle(%)=ON TimeTotal Time×100Duty\ Cycle(\%)=\frac{ON\ Time}{Total\ Time}\times100
Examples
0% Duty Cycle
Pin always OFF
Output = 0V
25% Duty Cycle
Pin ON 25% of the time
Output appears low
50% Duty Cycle
Pin ON half the time
Medium power
75% Duty Cycle
Pin ON most of the time
High power
100% Duty Cycle
Pin always ON
Full power
8. Visualizing Duty Cycle
0%
__________
Always OFF
25%
|_|____|_|____
50%
|__|__|__|__
75%
|____|_|____|_
100%
||||||||||||||
Always ON
9. What is Frequency?
PWM signals consist of repeated cycles.
The number of cycles per second is called:
Frequency
Unit:
Hertz (Hz)
Example
1 Cycle per Second
=
1 Hz
1000 Cycles per Second
=
1000 Hz
Arduino UNO PWM frequency is typically around:
490 Hz
for most PWM pins.
10. PWM and Voltage Relationship
PWM does not actually change voltage.
Arduino still outputs:
0V
or
5V
Only.
However the average voltage changes.
| Duty Cycle | Average Voltage |
|---|---|
| 0% | 0V |
| 25% | 1.25V |
| 50% | 2.5V |
| 75% | 3.75V |
| 100% | 5V |
This creates the illusion of analog voltage.
11. analogWrite() Function
Arduino uses:
analogWrite(pin,value);
for PWM output.
Syntax
analogWrite(pin,value);
Parameters
pin
PWM pin number
value
PWM value
Range:
0 to 255
Why 255?
Arduino uses:
8-bit PWM Resolution
Values:
0 – 255
Total:
256 Levels
PWM Value Examples
| PWM Value | Output |
|---|---|
| 0 | OFF |
| 64 | 25% |
| 128 | 50% |
| 192 | 75% |
| 255 | Full ON |
12. LED Brightness Control Example
void setup()
{
}
void loop()
{
analogWrite(9,50);
}
LED glows dimly.
analogWrite(9,128);
Medium brightness.
analogWrite(9,255);
Maximum brightness.
13. Motor Speed Control
PWM is commonly used for motors.
Example:
25% Duty Cycle
Motor rotates slowly.
50% Duty Cycle
Medium speed.
100% Duty Cycle
Maximum speed.
Why Motors Need PWM
Without PWM:
Motor only:
- Start
- Stop
With PWM:
Motor speed becomes controllable.
14. Applications of PWM
PWM is used everywhere.
LED Brightness Control
Adjust light intensity.
DC Motor Speed Control
Robot movement control.
Fan Speed Control
Airflow regulation.
Light Dimmers
Home automation systems.
Audio Signal Generation
Simple sound generation.
Robotics
Precise motion control.
15. PWM vs Digital Output
| Feature | Digital Output | PWM Output |
|---|---|---|
| Values | HIGH/LOW | 0–255 |
| Voltage | 0V or 5V | Simulated Analog |
| Brightness Control | No | Yes |
| Speed Control | No | Yes |
| Function | digitalWrite() | analogWrite() |
16. Common Beginner Mistakes
Mistake 1
Using analogWrite() on non-PWM pins.
Result:
PWM may not work.
Mistake 2
Using values above 255.
Wrong:
analogWrite(9,500);
Correct:
analogWrite(9,255);
Mistake 3
Expecting true analog voltage.
PWM is only a simulation.
Mistake 4
Confusing Analog Pins with PWM Pins.
PWM uses specific digital pins.
17. Real World Example
Line Follower Robot
Robot detects black line.
Arduino calculates correction.
PWM controls:
Left Motor Speed
Right Motor Speed
Result:
Smooth turning.
Without PWM:
Robot movement would be jerky.
18. Industrial Applications
PWM is widely used in:
- CNC Machines
- Industrial Robots
- Electric Vehicles
- Motor Drives
- Solar Systems
- Smart Home Devices
📊 Summary
In this lesson, we learned:
✅ What PWM is
✅ Why PWM is required
✅ PWM pins on Arduino UNO
✅ Duty Cycle
✅ Frequency
✅ analogWrite()
✅ LED brightness control
✅ Motor speed control
✅ Real-world applications
PWM is one of the most important concepts in embedded systems because it allows digital devices to behave like analog control systems.
📖 Key Terms
PWM
Pulse Width Modulation
Duty Cycle
Percentage of ON time in one cycle
Frequency
Number of cycles per second
Hertz
Unit of frequency
analogWrite()
Function used to generate PWM signals
PWM Pin
Pin capable of generating PWM output
🎯 Quiz
1. What does PWM stand for?
A. Pulse Width Modulation ✅
B. Power Wave Management
C. Pulse Wave Monitoring
D. Power Width Modulation
2. Which pins support PWM on Arduino UNO?
A. D3, D5, D6, D9, D10, D11 ✅
B. A0–A5
C. D0–D5
D. All pins
3. What is the range of analogWrite() values?
A. 0–100
B. 0–255 ✅
C. 0–512
D. 0–1023
4. Which function is used for PWM output?
A. digitalWrite()
B. analogRead()
C. analogWrite() ✅
D. digitalRead()
5. What is the duty cycle at PWM value 255?
A. 25%
B. 50%
C. 75%
D. 100% ✅
🏠 Assignment
Task 1
List all PWM pins available on Arduino UNO.
Task 2
Create a table showing PWM values and corresponding brightness percentages.
Task 3
Explain duty cycle with diagrams.
Task 4
Research three industrial applications of PWM.
Task 5
Write a simple Arduino program that gradually increases LED brightness using PWM.