Arduino Nano 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 Arduino Nano 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 Arduino Nano ESP32.
|Arduino Nano ESP32
|USB Cable Type-C
|NeoPixel RGB LED Strip
|5V Power Adapter
|(Optional) DC Power Jack
|(Recommended) Screw Terminal Adapter for Arduino Nano
Or you can buy the following sensor kit:
|DIYables Sensor Kit 30 types, 69 units
Overview of 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 Arduino Nano ESP32 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.
Arduino Nano ESP32 Code
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.
To get started with Arduino Nano ESP32, follow these steps:
- If you are new to Arduino Nano ESP32, refer to the tutorial on how to set up the environment for Arduino Nano ESP32 in the Arduino IDE.
- Wire the components according to the provided diagram.
- Connect the Arduino Nano ESP32 board to your computer using a USB cable.
- Launch the Arduino IDE on your computer.
- Select the Arduino Nano ESP32) board and its corresponding COM port.
- Open the Library Manager by clicking on the Library Manager icon on the left navigation bar of Arduino IDE
- Search “Adafruit NeoPixel”, then find the NeoPixel library by Adafruit
- Click Install button to install NeoPixel library.
- Copy the above code and open with Arduino IDE
- Click Upload button on Arduino IDE to upload code to Arduino Nano ESP32
- Check out the effect of the LED strip