From Blink to PWM.
- PWM — Pulse Width Modulation: switching a pin HIGH and LOW very quickly, controlling how long it stays ON during each cycle.
- Our Blink code demonstrates the same idea slowly: 500 ms ON + 500 ms OFF means 50% light, 50% dark. PWM speeds this up so our eyes blend the flashes into steady-looking light.
- Brightness comes from the light/dark time ratio: longer ON pulses produce more average light. The number of cycles per second stays the same.
- Arduino’s PWM setting is 0–255:
0 = always OFF; 255 = always ON; 128 ≈ half ON, half OFF.
- On Uno pin 9, each cycle is approximately 2 milliseconds. Each 1% = 0.02 ms = 20 microseconds of ON time. One step in the 0–255 setting is approximately 0.39%.
- Examples: 25% = 0.5 ms ON + 1.5 ms OFF; 50% = 1 ms ON + 1 ms OFF; 75% = 1.5 ms ON + 0.5 ms OFF.
- The pin switches between approximately 0 V and 5 V. We change the time spent at each level—not accumulate power or produce a steady intermediate voltage.
- More ON time → more average light → a brighter-looking LED.