Holiday Lights Hookup Guide a learn.sparkfun.com tutorial
Available online at: http://sfe.io/t601
Light Up the Holidays
‘Tis the season, let’s get to decorating! Nothing looks as festive as a bunch of bright, colorful lights concentrated into a tight space. And for that, I heartily recommend an addressable LED strip. It’s very bright, super vivid, and easy to hookup. This kit has the bare essentials for adding a strip of LEDs to your holiday shrub, ugly sweater or boring family member.
Kit Includes:
- 1 x SparkFun RedStick
- 1 x Battery Holder 4xAA with Cover and Switch
- 1 x LED RGB Strip - Addressable, Bare (1m)
- 4 x 1500 mAh Alkaline Battery - AA
Covered in This Tutorial
This tutorial covers all of the wiring and code necessary to light up a string of addressable LEDs with just a RedStick and a AA Battery Pack.
Required Materials
Besides the parts included in your kit, you’ll need to following tools:
- Soldering tools, including an iron and solder
- Wire Strippers
Suggested Reading
If you’ve never worked with addressable LEDs or with the RedStick, we recommend checking out these other guides first.
Battery Technologies
Light-Emitting Diodes (LEDs)
RedStick Hookup Guide
Wire Them Up
For the purposes of this tutorial, I’m going to assume that you have some very basic soldering experience. There are only a handful of connections that you’ll need to solder, so this isn’t a bad project to start with However, if you are using this as your introduction to soldering, we strongly suggest reading this tutorial first.
Addressable LED strips like the one in this kit tend to use a standardized 3-pin connector. This makes it easy to chain multiple LED strips together. Because the battery pack included with this project is not going to support a lot more than the 60 included LEDs, you may find it convenient to cut the female connector off the “out” end of the strip and solder it to the RedStick to make your LEDs detachable.
The diagram below illustrates the handful of connections that you’ll need to make. You’ll notice that the red and yellow wires from the LED strip are connected directly to the battery connector. You may be tempted to connect them to the GND and VCC pins on the RedStick, but don’t do that. The VCC pin draws current through the on-board voltage regulator, which isn’t rated for the high current that the LEDs require to operate. If powered from VCC, the regulator will definitely get hot and may fail altogether.
Click image for a closer look
Example Code
Once your LED strip is wired up, you can load some Arduino code onto the RedStick to animate the lights! For our example code, we’ll be making use of Adafruit’s fantastic NeoPixel library.
Click here to download a copy of both the example code, as well as the NeoPixel library. The library is located in the “Adafruit_NeoPixel” folder, and the example code is found in the “WS2812_Breakout_Example” folder.
You’ll need to install the library. For help there, check out our installing Arduino libraries tutorial.
We’ve broken down the example code into a few separate sketches that each have a festive animation. Since this is a holiday kit, I took the liberty of cooking up a few special addition animations as well:
Rainbow Cycle
This one is my favorite of the NeoPixel example animations. It scrolls through the entire rainbow of colors while evenly distributing the color spectrum across the LED strip.
language:c
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define PIN 2
Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
strip.begin();
strip.setBrightness(64);
strip.show(); // Initialize all pixels to 'off'
}
void loop() {
rainbowCycle(20);
}
void rainbowCycle(uint8_t wait) {
uint16_t i, j;
for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
for(i=0; i< strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
}
strip.show();
delay(wait);
}
}
// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
WheelPos = 255 - WheelPos;
if(WheelPos < 85) {
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
}
if(WheelPos < 170) {
WheelPos -= 85;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
WheelPos -= 170;
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}
Candy Chase
This is a little animation that I worked up based on the “Theater Chase” animation included in the NeoPixel example code. It creates a crawling lights effect in red on a white background, like an animated candy cane!
language:c
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define PIN 2
Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
strip.begin();
strip.setBrightness(64);
strip.show(); // Initialize all pixels to 'off'
}
void loop() {
candyChase(100);
}
void candyChase(uint8_t wait) {
for (int j=0; j<10; j++) { //do 10 cycles of chasing
for (int q=0; q < 3; q++) {
for (uint16_t i=0; i < strip.numPixels(); i++) {
strip.setPixelColor(i+q, 255,255,255); //turn every pixel white
}
for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+q, 255,0,0); //turn every third pixel red
}
strip.show();
delay(wait);
for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+q, 0); //turn every third pixel off
}
}
}
}
Snowflakes
This animation creates an array of randomly twinkling white pixels remenicant of snowfall.
language:c
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define PIN 2
Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
strip.begin();
strip.setBrightness(64);
strip.show(); // Initialize all pixels to 'off'
}
void loop() {
snowflakes(100);
}
void snowflakes(uint8_t wait) {
// Setup the pixel array
int pixel[60];
for(int p=0; p<60; p++){
pixel[p] = random(0,255);
}
// Run some snowflake cycles
for (int j=0; j<200; j++) {
// Every five cycles, light a new pixel
if((j%5)==0){
strip.setPixelColor(random(0,60), 255,255,255);
}
// Dim all pixels by 10
for(int p=0; p<60; p++){
strip.setPixelColor(p, pixel[p],pixel[p],pixel[p] );
pixel[p] = pixel[p] - 10;
}
strip.show();
delay(wait);
}
}
Iceflakes
Not a real thing, I know… It’s “Snowflakes” but blue instead of white.
language:c
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define PIN 2
Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
strip.begin();
strip.setBrightness(64);
strip.show(); // Initialize all pixels to 'off'
}
void loop() {
iceflakes(100);
}
void iceflakes(uint8_t wait) {
// Setup the pixel array
int pixel[60];
for(int p=0; p<60; p++){
pixel[p] = random(0,255);
}
// Run some snowflake cycles
for (int j=0; j<200; j++) {
// Every five cycles, light a new pixel
if((j%5)==0){
strip.setPixelColor(random(0,60), 0,0,255);
}
// Dim all pixels by 10
for(int p=0; p<60; p++){
strip.setPixelColor(p, 0,0,pixel[p] );
pixel[p] = pixel[p] - 10;
}
strip.show();
delay(wait);
}
}
Extending Battery Life
The 60 LEDs on your addressable LED strip can drain a lot of batteries really fast. At full brightness, the strip will pull over 2 amps!! With a capacity of only 1.5 amp-hours, the AA batteries included in this kit will only power the strip at full brightness, continuously, for under an hour. If you want to get more bang for your battery-buck, there are a few tricks you can use.
Cap the Brightness
60 LEDs in a linear meter is a lot of LEDs, so running them at full brightness is really… impressive. And mostly unnecessary. Luckily, the NeoPixel library includes a handy function called setBrightness();
which limits the brightness of an LED strip. You’ll notice that the examples in this tutorial all include the line strip.setBrightness(64);
, which sets the strip brightness to about 25%. You can set it lower before noticing a huge difference in brightness, so play with that number until you find the right balance between brightness and battery life.
Take a Break
Sometimes a cool lighting effect is more impressive if it isn’t continuous. Try dropping a delay();
into the main loop so that there’s some downtime between animation cycles. Obviously, the less time you leave the LEDs on, the longer your batteries will last.
Cut it Short
Maybe you don’t need 60 LEDs. Maybe 30 would do just fine. You can cut a portion off the end of the strip with a pair of standard craft scissors. Just cut across the copper pads in between the LEDs, and now you have another small strip you could use elsewhere. You can always solder them back together if you change your mind!
Resources and Going Further
Now go forth and add lights to everything! It’s worth noting that the RedStick in this kit is powerful enough to address a lot more than 60 LEDs, but you’ll need to beef up the power supply before you start chaining strips together.
Also, we’d love to see what you did with your light kit! Take a picture and tweet it to @sparkfun.
For more blinky fun, check out these other great SparkFun tutorials:
Cherry MX Switch Breakout Hookup Guide
learn.sparkfun.com |CC BY-SA 3.0 | SparkFun Electronics | Niwot, Colorado