Categories
TUTORIALS

TUTORIAL: HOW TO COMMAND INDIVIDUAL LEDS WITHIN AN RGB LED STRIP USING NEOPIXEL LIBRARY

Introduction:

Welcome to my Led Strip tutorial. This tutorial uses the Neopixel library by Adafruit. It is part of the Platy++ project, developed with Chin Yee Lee and Neil Narayan. It was originally done in an Arduino Uno. Here is what you are going to need:

If you landed here at this tutorial, chances are that you got everything but the LED strip. Perhaps you got already got your LED strip and cannot control it as you should. Do not worry, I learned it the hard way, so you don’t have to.

If you do have the same LED Strip from this tutorial, the code and instructions will already match your needs. But if you don’t, IT IS REALLY IMPORTANT to set the right parameters for your LED strip in the Arduino IDE. We will get there, but first things first, how do you wire this project?

As you surely noticed if the picture and diagram, most LED strips come with the wiring for both directly in your Arduino, as well as in an alternative source of power. Please notice the importance of using a 330Ω resistor, instead of wiring the signal directly to the Arduino Pin. This workaround enables a cleaner signal transmission.

Here is a picture of my installation, to make things clearer:

 

Installing the NeoPixel Library and setting up your Led strip:

There are two ways of installing the NeoPixel library:

  1. In your Arduino IDE, go to Tools > Manage Libraries (or Ctrl+Shift+I):

Search for the Adafruit NeoPixel and install it:

2. Alternatively, you can go to https://learn.adafruit.com/adafruit-neopixel-uberguide/arduino-library-installation and click on the green banner that says Download Adafruit_Neopixel for Arduino.

  • IMPORTANT: In this case, you have to extract the zip file and rename the folder. The zip file is named Adafruit_NeoPixel-master.zip, so it will create a folder named Adafruit_NeoPixel-master once extracted. Right click on the folder and select rename, and then remove the “-master” part of the name (The folder’s name should be just Adafruit_NeoPixel).
  • Copy the entire folder inside the Arduino Libraries Folder (Normally, it is on C: > Program Files (or Program Files (x86), if you are using Windows 10) > Arduino > libraries.
  • Restart the Arduino IDE before you use it.

OK, now that you got your library installed, let’s go over some initial setup IMPORTANT TIPS, before the real fun begins:

Make sure to learn which kind of LED you are using. Notice on the description of the strip we are using that this is an RGB White (or RGBW) LED, and it uses a WS2812B control. You can learn further about this by taking a look at the datasheet.

The reason why I mention it is because you are going to need to specify those parameters when you declare your variables. And inputting the correct data will make your installation work properly. Please read the comments on the code to ensure you got everything right.

And here you have the result:

Thanks for reading. I hope you have enjoyed going through this tutorial.

5 replies on “TUTORIAL: HOW TO COMMAND INDIVIDUAL LEDS WITHIN AN RGB LED STRIP USING NEOPIXEL LIBRARY”

Hello, I loaded the sketch,
but it does not work like it did on the video.
ws2811 connected 5 meters long.
Power supply 12 V 2A. what am I doing wrong ?
Greeting Lutz Germany

Hello Leonardo,
Thanks for your answer.
I’ll try it like you wrote me.
The power supply for the strip, I feed separately, only the data come from the Arduino.
Greeting Lutz

Hello Lutz,

It is difficult to determine what it can be without looking at everything. I was using a 1m LED strip. A 5m strip may be drawing too much power from the Arduino. Also:

– The sketch above is using a WS2812 LED Strip, thus NEO_GRBW + NEO_KHZ800. Check the datasheet of your strip to see if that is what you are supposed to use. I am almost sure you should input NEO_KHZ400. Check for the color scheme too (GRBW / GRB / RGBW / RGB). It should be in the datasheet. Adjust it in this line of the code:
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRBW + NEO_KHZ800);

– Did you adjust the arrays for the number of pixels in your strip?

I’d try that first

Hi there great bit of code.
I am trying to adapt it, so i can turn on each array at a set distance using a distance sensor.
My question is:
How do i control just one array at a time?

Hi Patrick,
I am not really sure if that will help you, but if you take a look at response #5 from this post:
http://forum.arduino.cc/index.php?topic=191269.0
That might help you. I guess another option would be to have an array within another array (I searched for that initially). But I am not really a coder. This tutorial was a DIY effort for a course I took last semester.

Leave a Reply

Your email address will not be published. Required fields are marked *