Arduino Nano - NeoPixel LED Strip
The NeoPixel RGB LED strip is a line of LEDs where the color and brightness of each one can be adjusted independently. This tutorial instructs you how to use an Arduino Nano to control the NeoPixel RGB LED strip. In detail, we will learn:
- How to connect the NeoPixel LED strip to Arduino Nano
- How to program Arduino Nano to control the color of each individual LED on the NeoPixel LED strip.
- How to program Arduino Nano to control the brightness of each individual LED on the NeoPixel LED strip.
All the LEDs on the strip can be controlled with only one digital pin of the Arduino Nano.
Hardware Preparation
Or you can buy the following sensor kits:
1 | × | DIYables Sensor Kit (30 sensors/displays) | |
1 | × | DIYables Sensor Kit (18 sensors/displays) |
Additionally, some of these links are for products from our own brand, DIYables.
Overview of NeoPixel RGB LED Strip
The NeoPixel LED Strip Pinout
The NeoPixel RGB LED Strip has three pins:
- GND pin: must be connected to GND (0V)
- VCC pin: must be connected to 5V of an external power source
- Din pin: is the pin that receives the control signal and should be connected to an Arduino Nano's digital pin.
※ NOTE THAT:
The order of pins may differ between manufacturers. It is imperative to always use the labels printed on the LED Strip.
Wiring Diagram
This image is created using Fritzing. Click to enlarge image
How To Program For NeoPixel RGB LED Strip
- Create a NeoPixel object.
- Initializes NeoPixel.
- Specify the color of each individual LED (known as a pixel).
- Adjust the brightness of all the strip.
※ NOTE THAT:
- NeoPixel.setBrightness() is used to adjust the brightness of all pixels on the LED strip. To set the brightness for each individual pixel, we can scale the color values (R,G, B) with the same ratio.
- The values set by NeoPixel.setBrightness() and NeoPixel.setPixelColor() will only be applied when NeoPixel.show() is called.
Arduino Nano Code
The code below does the following sequences:
- Turn pixels to green one-by-one with a delay between each pixel
- Turns off all pixels for two seconds
- Lights up all pixels in red for two seconds
- Repeats this process endlessly
Detailed Instructions
- Click to the Libraries icon on the left bar of the Arduino IDE.
- Search for “Adafruit NeoPixel” and locate the NeoPixel library by Adafruit.
- Then, press the Install button to install the NeoPixel library.
- Copy the code and open it in the Arduino IDE.
- Click the Upload button in the Arduino IDE to send the code to the Arduino Nano.
- Check out the LED effect.
※ NOTE THAT:
For any intricate LED effect, we provide the paid programming service