HomeESP8266/ESP32How to drive RGB LEDs with ESP32 & ESP8266

How to drive RGB LEDs with ESP32 & ESP8266

I'm LED mad! It's deLEDhtfull!

I’m starring at 410 individually addressable LEDs (WS2812b). They all blink in rainbow fashion driven by a test FastLED library. I have to say the road was bumpy and took me longer than I initially thought it would, to get here. The internet is lacking a clear set of instructions how to drive RGB LEDs with ESP32 & ESP8266. This is my contribution.

WS2812b RGB LEDs with ESP32 & ESP8266

I had some spare LEDs left from my automated staircase lights project. I had over 400 of them left to be precise. Previously, I used Arduino Nano to drive the LEDs. This was simple enough as both Arduino and individually addressable LEDs use the same 5V logic.

Arduino I used has no internet. I figured out, it would be nice to drive the LEDs with an ESP of some kind. To my surprise, there is more to level logic shifting than adding a module I had. Nothing worked until I consulted the internet. Turns out my LLC were too slow to deal with PWM signal. Since I knew what’s wrong, finding the suitable components was quick and easy. Well, it was easy, as I had to wait 4 weeks for the IC to be shipped.

The parts are here and I’m using an IC SN74HCT245 to handle the level shifting for me. The data sheet can be daunting if you never had to read one of these. Don’t worry, I will explain all the information you need to know.

I have tested the RGB LEDs with ESP32 & ESP8266, however, I think my project will end up running on ESP32 if I want to host a web server. I will have more processing power to handle the changes and the ESP32 should perform faster in that aspect.

SN74HTC245 or SN74HTC125

Take a look at the pin out of the IC.  You will see this chip can shift 8 (or 4 for SN74HTC125) channels in both directions. To properly connect the IC you have to also read this table:

Here is the schematic of how you should connect the IC to drive RGB LEDs with ESP32 & ESP8266. In my video I’m driving 410 LEDs with a single ESP32, you should be able to achieve the same with ESP28266.

Make sure that ESP’s share GND with LED’s power supply otherwise the lights won’t work properly. I was actually surprised how little power these 400+ LEDs has been using.  I never hit the 2A mark even when the brightness has been will find a colour palette sketch to try your lights. Don’t worry, I know the sketch says it’s for WS2811 LEDs. It will work just fine!

ARDUINO IDE: Color Palette

#define LED_PIN     2
#define NUM_LEDS    50
#define BRIGHTNESS  64
#define LED_TYPE    WS2811


CRGBPalette16 currentPalette;
TBlendType    currentBlending;

extern CRGBPalette16 myRedWhiteBluePalette;
extern const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM;

void setup() {
    delay( 3000 ); // power-up safety delay
    FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
    FastLED.setBrightness(  BRIGHTNESS );
    currentPalette = RainbowColors_p;
    currentBlending = LINEARBLEND;

void loop()
    static uint8_t startIndex = 0;
    startIndex = startIndex + 1; /* motion speed */
    FillLEDsFromPaletteColors( startIndex);
    FastLED.delay(1000 / UPDATES_PER_SECOND);

void FillLEDsFromPaletteColors( uint8_t colorIndex)
    uint8_t brightness = 255;
    for( int i = 0; i < NUM_LEDS; i++) {
        leds[i] = ColorFromPalette( currentPalette, colorIndex, brightness, currentBlending);
        colorIndex += 3;

void ChangePalettePeriodically()
    uint8_t secondHand = (millis() / 1000) % 60;
    static uint8_t lastSecond = 99;
    if( lastSecond != secondHand) {
        lastSecond = secondHand;
        if( secondHand ==  0)  { currentPalette = RainbowColors_p;         currentBlending = LINEARBLEND; }
        if( secondHand == 10)  { currentPalette = RainbowStripeColors_p;   currentBlending = NOBLEND;  }
        if( secondHand == 15)  { currentPalette = RainbowStripeColors_p;   currentBlending = LINEARBLEND; }
        if( secondHand == 20)  { SetupPurpleAndGreenPalette();             currentBlending = LINEARBLEND; }
        if( secondHand == 25)  { SetupTotallyRandomPalette();              currentBlending = LINEARBLEND; }
        if( secondHand == 30)  { SetupBlackAndWhiteStripedPalette();       currentBlending = NOBLEND; }
        if( secondHand == 35)  { SetupBlackAndWhiteStripedPalette();       currentBlending = LINEARBLEND; }
        if( secondHand == 40)  { currentPalette = CloudColors_p;           currentBlending = LINEARBLEND; }
        if( secondHand == 45)  { currentPalette = PartyColors_p;           currentBlending = LINEARBLEND; }
        if( secondHand == 50)  { currentPalette = myRedWhiteBluePalette_p; currentBlending = NOBLEND;  }
        if( secondHand == 55)  { currentPalette = myRedWhiteBluePalette_p; currentBlending = LINEARBLEND; }

void SetupTotallyRandomPalette()
    for( int i = 0; i < 16; i++) {
        currentPalette[i] = CHSV( random8(), 255, random8());

void SetupBlackAndWhiteStripedPalette()
    // 'black out' all 16 palette entries...
    fill_solid( currentPalette, 16, CRGB::Black);
    // and set every fourth one to white.
    currentPalette[0] = CRGB::White;
    currentPalette[4] = CRGB::White;
    currentPalette[8] = CRGB::White;
    currentPalette[12] = CRGB::White;

void SetupPurpleAndGreenPalette()
    CRGB purple = CHSV( HUE_PURPLE, 255, 255);
    CRGB green  = CHSV( HUE_GREEN, 255, 255);
    CRGB black  = CRGB::Black;
    currentPalette = CRGBPalette16(
                                   green,  green,  black,  black,
                                   purple, purple, black,  black,
                                   green,  green,  black,  black,
                                   purple, purple, black,  black );

const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM =
    CRGB::Gray, // 'white' is too bright compared to red and blue

I used Arduino IDE and the FastLED library to drive the LEDs.  You can install this library directly through the Library Manager. The sketched used by me to test the matrix is the Color Palette. Adjust the following details:

#include <FastLED.h>

#define LED_PIN 2 //signal pin 
#define NUM_LEDS 50 //number of LEDs in your strip
#define BRIGHTNESS 64  //brightness  (max 254) 
#define LED_TYPE WS2811  // I know we are using ws2812, but it's ok!


I hope this short article will help you with your project. Driving RGB LEDs with ESP32 & ESP8266 is fun and enables a lot of functionality, that was not possible with Arduino Nano. My next project will involve the set up presented to you! I have included the project file and the IC datasheet for you in the download link. If you want to learn more about how to power this monster of a matrix check out this post.

Project Download

Download project files here. Bear in mind that Patreon supporters have early access to project files and videos.


Nothing says "Thank you" better than keeping my coffee jar topped up!


Support me on Patreon and get an early access to tutorial files and videos.


Bitcoin (BTC)

Use this QR to keep me caffeinated with BTC: 1FwFqqh71mUTENcRe9q4s9AWFgoc8BA9ZU


Programable, ESP32 based awesome dev platform with 4.7 e-ink display by M5Stack

More HATs


Argon One M.2

Enclose Raspberry Pi 4 inside this great case with custom I/O, cooling and GPIO and M.2 SSD support

More cases on


Best Raspberry Pi Projects

How to use Raspberry PI as WOL (wake on lan) server

While you could wake up your PC from a mobile directly, having a dedicated server capable of doing so is the best solution. The reason is simple. You can hook up as many devices as you wish with a single endpoint. This is why Raspberry Pi is perfect for this.

How fast Raspberry Pi NAS is?

Let's see how fast Raspberry Pi NAS really is?

Argon18: Argon ONE SSD modification

Argon One case just got better - now you can boot it from USB without ruining the design thanks to Argon 18: Argon One SSD modification

The most pointless upgrade to my NAS – Raspberry Pi 3B+

This upgrade is almost pointless!


C/C++ and MicroPython SDK for Raspberry Pi Pico on Windows

A guide to SDK toolchain for Raspberry Pi Pico and C/C++ , Micropython on Windows.

A comprehensive guide to Grafana & InfluxDB

How to use Grafana and InfluxDB on Raspberry Pi for IoT sensors in home automation

How to boot Raspberry Pi 4 from USB

How to set up and boot Raspberry Pi 4 from USB drive - headless guide.

Raspberry Pi Zero, Raspberry Pi 3A+ WiFi without keyboard or cables

Getting Raspberry Pi boards connected in seconds

Everything you need to start using JSON

It's JSON not Jason, just saying!