Skip to content

Pulsing an LED with ESPHome

I might be dating myself, but I loved the way old Mac’s in my high school’s computer lab would pulse the LED when the unit was in standby mode. While I love how easy ESPHome makes it possible to make a wild variety of custom applications, smoothly pulsing an LED isn’t one of them.

I did some searching and found a good write up by SparkFun that walked you through a way of achieving it. Basically, you can leverage the sin function’s smooth output and appropriately scale/offset that output to drive your LED output.

Making it happen

The code below is running on my dining room switch as a lighting effect on a single pixel of WS2812. I’ve included some comments to help understand some of the pieces and how you can tailor it for your application.

  • Speed
    • Change the update_interval to .15s to slow down the pulsing loop
  • Color & Brightness
    • Change the 1.0, 0.0, 0.0 to R, G, B color values (0-1.0) to set color and brightness
  • Resolution
    • Change the step size of the pulse loop

‚Äč

The pulsing glory

Here’s what it looks like in action:

Published inESPHome