RGB LED strip NeoPixel

This project is about the WS2812B LED strip, which is an addressable RGB LED strip. The information in this project also works with other similar LED strips, such as strips of the WS28XX family, Neopixel strip and others.

Video Tutorial

you can watch this video tutorial

Hardware Required

1×ESP-WROOM-32 Dev Module
1×Micro USB Cable
1×rgb LED strip
1×Breadboard
n×Jumper Wires

Introduction to WS2812B LED Strip

The WS2812B addressable LED strip comes in several models that differ in size, sealant or LED density. Choose the one that best fits your purposes.

In the following figure you can see a WS2812B LED strip. It is 5 meters long and the LEDs are enclosed in a weatherproof silicone. So, they can be left outside at the rain and dust without any problem.

ESP32 Button LED Wiring Diagram

You can control the brightness and the color of each LED individually, which allows you to produce amazing and complex effects in a simple way.

This LED strip is made by WS2812B LEDs wired in series. These LEDs have an IC built right into the LED. This allows a communication via a one-wire interface. This means that you can control lots of LEDs using just one digital pin of your esp32.

In the following figure you can see the chip inside the LED. The LED is an RGB LED and works like so.

ESP32 Button LED Wiring Diagram

This kind of strips are very flexible and can be cut to any length you want. As you can see, the strip is divided into segments, and each segment contains one RGB LED.

ESP32 Button LED Wiring Diagram

You can adjust its size by cutting the strip with a scissors in the right place (the proper places to cut the strip are marked).

ESP32 Button LED Wiring Diagram

These strips come with connectors at each end. I’ve decided to cut the connectors, and solder header pins. It’s more handy if you want to connect the strip to an esp32 or to a breadboard.

ESP32 Button LED Wiring Diagram

Powering the WS2812B LED Strip

The LED strip should be powered using a 5V power source. At 5V, each LED draws about 50mA, when set to its full brightness. This means that for every 30 LEDs, the strip may draw as much as 1.5 A. Make sure you select a power source that matches the strip’s needs. An AC to DC power adapter that provides 5V and 2A should do the job:

  • 5V 2A power adapter

If you use an external power source, don’t forget to connect the power source ground to the esp32 ground.

Wiring Diagram

Breadboard Connections

ESP32 Button LED Wiring Diagram

Image is developed using Fritzing. Click to enlarge image

click to see ESP32 pin out

ESP32 Code

To control the WS2812B LED strip, you’ll need to download the Adafruit_NeoPixel library.

Installing the Adafruit_NeoPixel library

  • Click here to download the Adafruit_NeoPixel library. You should have a .zip folder in your Downloads folder
  • Unzip the .zip folder and you should get Adafruit_NeoPixel-master folder
  • Rename your folder from Adafruit_NeoPixel-master to Adafruit_NeoPixel
  • Move the Adafruit_NeoPixel folder to your Arduino IDE installation libraries folder
  • Finally, re-open your Arduino IDE

After installing the needed library, upload the following code to your esp32 board

Copy

#include <Adafruit_NeoPixel.h>

#define PIN      4
#define N_LEDS 60

Adafruit_NeoPixel strip = Adafruit_NeoPixel(N_LEDS, PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  strip.begin();
}

void loop() {
  chase(strip.Color(255, 0, 0)); // Red
  chase(strip.Color(0, 255, 0)); // Green
  chase(strip.Color(0, 0, 255)); // Blue
}

static void chase(uint32_t c) {
  for(uint16_t i=0; i<strip.numPixels()+4; i++) {
      strip.setPixelColor(i  , c); // Draw new pixel
      strip.setPixelColor(i-4, 0); // Erase pixel a few steps back
      strip.show();
      delay(25);
  }
}            

Quick Steps

  • power up your board
  • Open Arduino IDE
  • Select the right board
  • Select the right port
  • Copy the above code and open with Arduino IDE
  • Click Upload button on Arduino IDE to upload code to ESP32
  • Arduino IDE Upload Code
  • Press and keep pressing the button several seconds
  • See the changes you made

Book Tutorial

We are considering to make the book tutorials. If you think the book tutorials are essential, you can download it. download book

References

※ NOTE THAT:

Some components works on 3.3v and others works on 5v!