LED Light (Addressable) Operation + Arduino

From ESE205 Wiki
Jump to: navigation, search

Know Your LEDs

This is a tutorial for Addressable LED Strips that operate off of the Adafruit NeoPixel Library. Check your LEDs' data sheet and product info for what library your LEDs operate on. If your LEDs operate on one single digital pin, it is likely that they will operate on the NeoPixel Library. If they require a clock line, they do not operate on the NeoPixel library.

These LED strips function on this library. Many others do as well.

The Basics of Your LEDs

Your LEDs are addressable. This means that you can tell each pixel what color to be. And, further, you can hand each pixel an RGB value, meaning you can set any pixel to any color. This gives you a lot of freedom, but it can be quite daunting. Have no fear! Your LEDs are very easy to control. The NeoPixel library comes with a ready-to-go demo that you can push right to your Arduino to make your lights operate.

Wiring your LEDs

Your LEDs are likely cut-able, meaning you can cut them to however small your project requires. This cutting does not impact your coding at all! The closest LED pixel to the Arduino on a strip is always considered the first pixel.

Your LEDs are likely directional, meaning the wires must be soldered to a specific end of your length of LEDs. Once you cut to your desired length, locate the direction of the arrows on the LEDs strip. You want these arrows to point away from the 3 wires you're going to solder on.

Once you've cut the LEDs to length and have located where you need to solder, solder your 3 wires on (Ground (GND), Signal (DO, or "Digital Out"), and Power ("5V")) using this wonderful student tutorial.

Then, connect the Signal, Ground, and Power to the appropriate places:

  • Signal goes to the pin on your Arduino
  • Ground goes to the black port on your power supply
  • Power goes to the red port on your power supply

For information on how to use power supplies, see this tutorial.

You are now ready to play around with your LEDs!

Getting the Library

The Adafruit NeoPixel Library is a library of code needed to operate your lights. It is open sourced and you can download it here.

For instructions on how to set up the library, look here.

Controlling Your LEDs

Once the library is properly imported, you can begin to use it.

The basic commands to interact with your lights are as follows:

  • Create the strip so you can control it. This needs to be done before the "setup" for each strip. Replace the italicized values with your own.
          Adafruit_NeoPixel nameOfLEDStrip = Adafruit_NeoPixel (lengthOfStrip, pinNumber, NEO_GRB + NEO_KHZ800);
  • Begin the connection. This must be done in the "setup" loop for each strip. Again, replace the italicized values with your own.
                                              nameOfLEDStrip.begin();
  • Tell a pixel what color to be. Each pixel can be addressed individually. This can be done anywhere in the code. The red, green, and blue vales can range from 0 to 128. To see what colors you can make with RGB, see the NeoPixel library, or this chart. Again, replace the italicized values with your own.
                  nameOfLEDStrip.setPixelColor(pixelNumber, redValue, greenValue, blueValue);

  • Tell the LED strip to display its colors. This can be done anywhere in the code. Again, replace the italicized values with your own.
                                              nameOfLEDStrip.show();