Skip to content
06 25 minutes

Breathing LED

Fading light with pulse width modulation

Breathing LED project
Illustration of the finished idea. Build from the diagram and connection table, not the photo.

Mission goal: Use PWM at 1000 Hz on GP16 to fade the LED smoothly up and down, and understand why the pin is still only ever at 0 V or 3.3 V.

Section 1

Understand

New ideas

  • Pulse width modulation and duty cycle
  • duty_u16 from 0 to 65535
  • Average brightness versus actual pin voltage
  • Cleaning up PWM with deinit
  • 1PWM flicks the pin on and off very fast.
  • 2More time on (duty) looks brighter. The pin is only ever 0 V or 3.3 V.
  • 3Counting duty up then down makes the LED breathe.

Safety first

  • Wiring is unchanged from Mission 01, so unplug only if you need to reseat something.
  • Keep the 1 kΩ resistor. PWM does not remove the need for current limiting.