ESP32 - WS2812B LED Strip
In this tutorial, we are going to learn how to use ESP32 to control WS2812B RGB LED strip. With a single ESP32 pin:
- ESP32 can control the color of each LED on the led strip individual
- ESP32 can change the brightness of each LED on the led strip individual
Hardware Used In This Tutorial
|ESP-WROOM-32 Dev Module
|USB Cable Type-C
|WS2812B RGB LED Strip
|5V Power Adapter
|(Optional) DC Power Jack
|(Recommended) ESP32 Screw Terminal Adapter
Or you can buy the following sensor kit:
|DIYables Sensor Kit 30 types, 69 units
Introduction to WS2812B RGB LED Strip
the WS2812B RGB LED Strip has three pins:
- GND pin: needs to be connected to GND (0V)
- VCC pin: needs to be connected to 5V of external power supply
- Din pin: is pin that receives the control signal. It should be connected to a ESP32 pin.
※ NOTE THAT:
The order of pins can vary between manufacturers. ALWAYS use the labels printed on the LED Strip.
This image is created using Fritzing. Click to enlarge image
If you're unfamiliar with how to supply power to the ESP32 and other components, you can find guidance in the following tutorial: How to Power ESP32.
How To Program For WS2812B RGB LED Strip
- If this is the first time you use ESP32, see how to setup environment for ESP32 on Arduini IDE.
There are two libraries can be used to control WS2812B led strip:
- Adafruit NeoPixel library.
- FastLED library.
This tutorial will use the Adafruit NeoPixel library
- Declare a WS2812B object
- Initializes the WS2812B
- Set color of each individual LED (called pixel).
- Set brightness of all strip.
※ NOTE THAT:
- WS2812B.setBrightness() is used for all pixel on LED strip. To set the brightness for each individual pixel, we can scale the color value.
- The values set by WS2812B.setBrightness() and WS2812B.setPixelColor() only take effect when WS2812B.show() is called.
The below code does:
- Turn pixels to green one by one with a delay between each pixel
- Turn off all pixels for two seconds
- Turn on all pixels to red at the same time for two seconds
- Repeat the above process infinitely
- Click to the Libraries icon on the left bar of the Arduino IDE.
- Search “Adafruit NeoPixel”, then find the WS2812B library by Adafruit
- Click Install button to install NeoPixel library.
- Copy the above code and open with Arduini IDE
- Click Upload button on Arduini IDE to upload code to ESP32
- See the LED effect
※ NOTE THAT:
For any complicated LED effect, we offer the paid programming service
Making video is a time-consuming work. If the video tutorial is necessary for your learning, please let us know by subscribing to our YouTube channel , If the demand for video is high, we will make the video tutorial.