Controlling LED strips using PWM in ESPHome

Disclosure: This post contains affiliate links. If you click through and make a purchase, I will earn a commission, at no additional cost to you. Read my full disclosure here.

In this tutorial, we'll explore how to use dumb LED strips, or non-individually addressable options, with ESPHome. Unlike the popular WS2812B and SK6812 chips, these LED strips with only two pins require pulse-width modulation (PWM) for control.

The appeal of individually addressable LED strips wears thin

Accent lighting using individually addressable LED strips can add a touch of excitement to any smart home. These LED strips offer a rainbow of colours and even animation options using ESPHome. However, their light quality often leaves something to be desired, causing many to steer clear of them for primary lighting.

Though colourful lights may be entertaining at first, they typically lose their novelty after a while. As a result, many users revert to plain white lighting. Unfortunately, RGB strips lacking a white channel, such as the WS2812B, are unable to produce a pleasing white colour, rendering them unsuitable for main lighting. This is where high CRI white LED strips come into play.

Green, white, and red LED strips inside of so-called infinity cubes, which use mirrors to make it look like there is no end to the box.§
Not all LED strips have to be flashy

The CRI of an LED strip is an indicator of how accurately it can represent the colours of various objects compared to an ideal or natural light source. A high CRI (typically 95+) is essential for video and photography work, as it presents colours more naturally. Some simply prefer high-quality lighting in their homes for a more authentic and visually pleasing environment.

The high CRI dilemma with addressable LED strips

When it comes to addressable LED strips, such as the widely used WS2812B or SK6812 chips, you might find yourself in a bit of a pickle. Most of these strips don't even mention their Colour Rendering Index (CRI) because, in all likelihood, it's not much to brag about. Manufacturers often skip measuring CRI to keep the price tag low. So, if you're seeking budget-friendly addressable LED strips, be prepared to make peace with this compromise. It's worth noting that high CRI addressable LED strips are few and far between, and when you do find them, they burn a hole in your pocket. One such example is YUJILEDS, a company that caters to video and photography enthusiasts, where a mere 5 meters can set you back around $300.

Fear not, for there is a silver lining: “dumb” or traditional LED strips. While they lack the individual addressability of their smarter counterparts and can't be dimmed on their own (though there are workarounds), they make up for it with affordability and high CRI availability. These strips come with only two pins for power delivery, and none for commands. The catch? They can only display a single colour temperature, so you can't tweak it as daylight fades. However, in spaces like the kitchen, where adjustable temperature isn't a necessity, high CRI traditional LED strips shine as the ideal lighting solution.

A kitchen, used to demonstrate functional lighting. There are two lampshades, four spotlight, and under-cabinet lighting. All lights produce a pleasing white illumination.

Mastering the art of dimming traditional LED strips with ESPHome

When it comes to dimming traditional LED strips, we have two primary methods at our disposal: voltage regulation and pulse-width modulation (PWM). While voltage regulation might have its merits, implementing it through ESPHome could turned out to be a daunting task. On the other hand, PWM triumphs in ease of use and compatibility with ESPHome.

Voltage regulators, although useful, tend to generate a significant amount of heat, necessitating either passive or active cooling. Contrarily, PWM demonstrates its prowess by swiftly alternating the LED strip between its on and off states (pulsing). This ingenious approach allows for the adjustment of brightness by merely tweaking the ratio of on-time to off-time.

YouTube video

This seamless transition leads us to spotlight an exemplary ESPHome project that has already accomplished what many of us desire. The adage “why reinvent the wheel” rings true here, as GitHub user eoncire has skilfully crafted under-cabinet lighting for their kitchen using high CRI traditional LED strips governed by an ESP32. It comes as no surprise that the firmware for the ESP32 was ingeniously developed using ESPHome.

An ESP32 board running ESPHome controlling high CRI LED strip

Essential components for high CRI LED strip control

Embarking on an ESPHome project to control high CRI LED strips calls for a collection of specific components, besides the standard electronics equipment such as a soldering iron. Key items include an ESP32 board, a MOSFET, and a resistor. Let's explore these essential elements in more detail.

The versatile ESP32 board

An ESP32 board serves as the foundation for this project, thanks to its two major advantages. Firstly, many ESP32 boards come with a built-in voltage regulator, enabling them to be powered directly by a 12V power supply. This conveniently matches the LED strip's voltage requirements, eliminating the need for a separate down-regulator for both components. Secondly, the ESP32 outshines the ESP8266 with its hardware-based PWM output. Multiple GPIO pins on ESP32 boards are also PWM-capable, allowing for seamless control of various zones using a single board.

MOSFET: the pulse-handling powerhouse

To manage the PWM pulses generated by the ESP32 board, a MOSFET becomes an integral component. A MOSFET (Metal-Oxide-Semiconductor Field-Effect Transistor) is a type of transistor commonly used in electronic devices for amplification and switching applications. MOSFETs are known for their high input impedance, low power consumption, and fast switching capabilities, making them ideal for various applications in modern electronics.

Acting as a voltage and current flow regulator between the source and drain, the MOSFET serves as a switch in this ESPHome node. It's essential to select a MOSFET compatible with the 3.3V voltage that the GPIO pins operate at.

Power supply: the driving force

As with any electronics endeavor, a power supply suited to the combined needs of your components is crucial. Carefully calculate your LED strip's power requirements and choose a fitting unit. Alternatively, you can opt for multiple power supplies for different strips, as demonstrated by the project's creator.

The finishing touches

To round off your project, gather supplementary items such as a breadboard or prototype PCB, a 10k ohm resistor, jumper wires, a soldering iron, and screw terminals for connecting the LED strip wires. For a comprehensive list of the hardware used in this project, along with schematics and wiring information, visit the creator's GitHub repository.

Crafting the Firmware with ESPHome

Now that all components are connected to the ESP32 board, it's time to develop the firmware for this project using ESPHome. The creator has generously shared their firmware on pastebin, making it easily accessible. The firmware is simple and straightforward, utilizing the ESP32 LEDC Output component in ESPHome. By using this component, the strip manifests as a dimmable light when integrated with Home Assistant.

An Essential ESPHome Endeavour

Let's be honest, previous ESPHome projects I've showcased were more about adding a touch of luxury or even a bit of novelty to your smart home setup – from a video doorbell to an automatic cat feeder. However, this project serves a fundamental purpose in today's smart homes, offering high-quality, dimmable lighting for everyday tasks like cooking and food preparation, all while seamlessly integrating with Home Assistant.

A portrait photo oif Liam Alexander Colman, the author, creator, and owner of Home Assistant Guide wearing a suit.

About Liam Alexander Colman

is an experienced Home Assistant user who has been utilizing the platform for a variety of projects over an extended period. His journey began with a Raspberry Pi, which quickly grew to three Raspberry Pis and eventually a full-fledged server. Liam's current operating system of choice is Unraid, with Home Assistant comfortably running in a Docker container.
With a deep understanding of the intricacies of Home Assistant, Liam has an impressive setup, consisting of various Zigbee devices, and seamless integrations with existing products such as his Android TV box. For those interested in learning more about Liam's experience with Home Assistant, he shares his insights on how he first started using the platform and his subsequent journey.

Leave a comment

Share to...