Arduino powered Christmas LED Strip


This next project is just in time for the holiday season, though it is really my fiddling with the code that came with the libraries for a 32 LED strip from Adafruit. Last year I had bought a single 1 meter 32 LED strip to play around with (video), but this year I decided to go with a 5 meter 160 LED strip to place outdoors for the Holidays.

Materials needed:

  • LPD8806 32 RGB LED Strip from Adafruit I implemented this outdoors with a full roll of 160 LEDs (5 orders)
  • Female DC Power adapter (I used this one also from Adafruit)
  • 5V 10A power supply
  • Arduino Uno
  • 4-pin JST SM Receptacle (optional)
  • Jumper wires – male/male and female/female (optional)

Simply follow the instructions in the Adafruit tutorial. If you don’t order a full roll, you will need to be able to solder a surface mount in order to attach the wires needed for the LED strip. Last year, I had stripped off one end of some jumper wires, soldered them to the LED strip as outlined in the tutorial above, then wrapped the end in some black electrical tape.

Surface mounts

This year however, I bought a whole roll and therefore used a 4-pin JST SM Receptacle to connect to the plug on the end of the LED Strip. To make the project easier to assemble and disassemble, I stripped one end of the JST SM connector, and soldered that to one end of a female/female jumper wire, as below.

IMG_0582 IMG_0584

Once the Arduino is mounted in a case, and male/male jumper wires are plugged into the correct pins, it looked like this, which I then connected the female jumper wires on the JST SM connector appropriately and then boxed it up to protect it from the elements.

IMG_0581

Seperately, I mounted the LED strip to our deck railing (with tape) – because we’re using the JST SM connector, it’s easy to disconnect the Arduino and power supplies in bring them in if the weather is bad, leaving the LED strip in place.

Now, because the product description says the LED strip “comes with a weatherproof sheathing” I decided to but it to the test of Colorado weather in December, as seen in the video above.

Finally the code:

/*
 * LED Strip - Christmas Theme
 *
 * by: Keith Kay
 * 12/20/2014
 * CC by-sa v3.0 - http://creativecommons.org/licenses/by-sa/3.0/
 * https://keithkay.com
 *
 * This sketch displays a bitmap or series of bitmaps on a 8x8 LED matrix, and implements the following
 * functionality:
 * - supports a variable number of frames as defined by the constant "frames"
 * - use of a potentometer to control the frame rate
 *
 * Portions of this code from:
 * "strandtest" by Adafruit - https://github.com/adafruit/LPD8806
 *
 */

#include "LPD8806.h"
#include "SPI.h"

int i,j;

// Number of RGB LEDs in strand:
int nLEDs = (32 * 5); // or 160, each meter has 32 LEDs, and I use this code for a 1 meter strip as well, so I just change the # of strips here

// Chose 2 pins for output; can be any valid output pins:
int dataPin  = 2; // blue wire
int clockPin = 3; // green wire
LPD8806 strip = LPD8806(nLEDs, dataPin, clockPin);

void setup() {
  // Start up the LED strip
  strip.begin();

  // Update the strip, to start they are all 'off'
  strip.show();
}

void loop() {
  
  colorChase(strip.Color(127,   0,   0), 25, 1, 1); // Red
  colorChase(strip.Color(127,   0,   0), 25, -1, 1); // Red
  colorChase(strip.Color(  0, 127,   0), 25, 1, 1); // Green
  colorChase(strip.Color(  0, 127,   0), 25, -1, 1); // Green
  
  colorWipe(strip.Color(127,   0,   0), 5, 1, 1);  // Red
  colorWipe(strip.Color(  0, 127,   0), 5, -1, 1);  // Green
  colorWipe(strip.Color(127,   0,   0), 5, 1, 2); // Red
  delay(1000);
  
  alternateBlink(500, 50);
  fadeRedtoGreen(100);
  delay(200);
}

/* Sketch functions */

// Chase one dot down the full strip.
void colorChase(uint32_t c, uint8_t wait, int dir, int interval) {
  int i;

  // Start by turning all pixels off:
  for(i=0; i<strip.numPixels(); i++) strip.setPixelColor(i, 0);

  // Then display one pixel at a time:
  if (dir == 1) {
    for(i=0; i<strip.numPixels(); i += interval) {
      strip.setPixelColor(i, c); // Set new pixel 'on'
      strip.show();              // Refresh LED states
      strip.setPixelColor(i, 0); // Erase pixel, but don't refresh!
      delay(wait);
    }  
  } else {
    for(i=(strip.numPixels()-1); i>=0; i -= interval) { // We take one off the value to eliminate a 'double flash'
      strip.setPixelColor(i, c); // Set new pixel 'on'
      strip.show();              // Refresh LED states
      strip.setPixelColor(i, 0); // Erase pixel, but don't refresh!
      delay(wait);
    }     
  }

  strip.show(); // Refresh to turn off last pixel
}

// Fill the dots progressively along the strip.
void colorWipe(uint32_t c, uint8_t wait, int dir, int interval) {
  int i;

  if (dir == 1) {
    for (i=0; i < strip.numPixels(); i += interval) {
      strip.setPixelColor(i, c);
      strip.show();
      delay(wait);
    }
  } else {
    for(i=(strip.numPixels()-1); i>=0; i -= interval) { // We take one off the value to eliminate a 'double flash'
      strip.setPixelColor(i, c);
      strip.show();
      delay(wait);
    }
  }
}

void alternateBlink (uint8_t wait, int duration) {
  uint32_t stripColorArray[strip.numPixels()]; // We need somewhere to store the LEDs
  uint32_t pixelTest;
  
  for (i=0; i<strip.numPixels(); i++) {
    stripColorArray[i] = strip.getPixelColor(i);
  }
  
  // first pass thru to turn off alternate pixels
  for (i=0; i<strip.numPixels(); i += 2) {
        strip.setPixelColor(i, 0); // Erase pixel, but don't refresh!
  }
  strip.show();
  delay(wait);
  
  // now keep passing thru alternating blinks
  for (j=0; j<duration; j++) {
    // pass thru the strip and check if the pixel is on or off and flip accordingly
    for (i=0; i<strip.numPixels(); i++) {
      pixelTest = strip.getPixelColor(i);
      if (pixelTest == 0) {
        strip.setPixelColor(i, stripColorArray[i]); // restore the color from the array
      } else {
        strip.setPixelColor(i, 0); // erase pixel
      }
    }
    strip.show();
    delay(wait);
  }
}

void fadeRedtoGreen(uint8_t wait) {
  for (i=0; i < 127; i++) {
    for (j=0; j < strip.numPixels(); j++){
      strip.setPixelColor(j, 127-i,i,0);
    }
    strip.show();
    delay(wait);
  }
}  

One thought on “Arduino powered Christmas LED Strip”

  1. Sorry about that. I don’t have the package the LED’s came in, but think you are ccorert on Common Cathode as to light them in arduino I wrote a HIGH. I will pick up some Common Anode from radioshack tonight. I Have 5 TLC5940 chips and don’t care if I use them all. The reason why I’m going with DIP is to use a breadboard (baby steps). After I get it working I’ll switch to surface mount. Nov 8 at 14:32

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.