🔌Pulse-Width Modulation (PWM)
Also known as PWM, PWM Pin, analogWrite, Duty Cycle
Turning a pin on and off very fast. It dims a light or slows a motor.
Think of it like
It is like flicking a light on and off so fast it looks half bright.
Example
On an Arduino Uno, analogWrite takes 0 to 255. A value of 64 keeps an LED on about a quarter of the time, so it glows dim.
Why it matters
Digital pins can only be on or off. PWM is how they dim lights, mix colours and set motor speed.
Definition
Example code
cpp
analogWrite(9, 64); // pin 9 on about a quarter of the timeCommon mistake
Key takeaways
- 1Fast switching. On and off many times a second.
- 2Duty cycle. The share of time it is on.
- 3Looks smooth. Eyes and motors see the average.