ESP32 - NeoPixel LED Strip
The NeoPixel strip is like a strip of colorful RGB LEDs, and you can control each LED's color and brightness on its own. In this guide, we'll discover how to use an ESP32 to control the NeoPixel RGB LED strip. To control all the LEDs on the NeoPixel strip, you only need a single pin on the ESP32.
Hardware Used In This Tutorial
|1||×||ESP-WROOM-32 Dev Module|
|1||×||Micro USB Cable|
|1||×||NeoPixel RGB LED Strip|
|1||×||5V Power Adapter|
|1||×||(Optional) DC Power Jack|
|1||×||(Optional) ESP32 Screw Terminal Adapter|
Or you can buy the following sensor kit:
|1||×||DIYables Sensor Kit 30 types, 69 units|
Introduction to NeoPixel RGB LED Strip
The NeoPixel 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 an ESP32 GPIO pin.
This image is created using Fritzing. Click to enlarge image
How To Program For NeoPixel RGB LED Strip
- Declare a NeoPixel object
- Initializes the NeoPixel
- Set color of each individual LED (called pixel).
- Set brightness of all strip.
※ NOTE THAT:
- NeoPixel.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 NeoPixel.setBrightness() and NeoPixel.setPixelColor() only take effect when NeoPixel.show() is called.
The following code accomplishes the following tasks:
- It sequentially changes pixels to green, with a pause between each pixel.
- It turns off all pixels for a duration of two seconds.
- It simultaneously sets all pixels to red, maintaining this state for 1 second.
- This entire process is then repeated indefinitely.
- If this is the first time you use ESP32, see how to setup environment for ESP32 on Arduino IDE.
- Do the wiring as above image.
- Connect the ESP32 board to your PC via a micro USB cable
- Open Arduino IDE on your PC.
- Select the right ESP32 board (e.g. ESP32 Dev Module) and COM port.
- On Arduino IDE, Go to Tools Manage Libraries
- Search “Adafruit NeoPixel”, then find the NeoPixel library by Adafruit
- Click Install button to install keypad library.
- Copy the above code and open with Arduino IDE
- Click Upload button on Arduino IDE to upload code to ESP32
- Check out the effect of the LED strip
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.