Quantcast
Channel: SparkFun Tutorials
Viewing all articles
Browse latest Browse all 1123

Holiday Lights Hookup Guide

$
0
0

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.

Cyber Monday Light Up the Holidays

KIT-14060

Kit Includes:

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:

Suggested Reading

If you’ve never worked with addressable LEDs or with the RedStick, we recommend checking out these other guides first.

Battery Technologies

The basics behind the batteries used in portable electronic devices: LiPo, NiMH, coin cells, and alkaline.

Light-Emitting Diodes (LEDs)

Learn the basics about LEDs as well as some more advanced topics to help you calculate requirements for projects containing many LEDs.

WS2812 Breakout Hookup Guide

How to create a pixel string with the WS2812!

RedStick Hookup Guide

Learn about the SparkFun RedStick, a USB thumb drive-sized Arduino-compatible development platform.

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.

Warning:Make sure you’re cutting the right connector! Look at the little black arrows on the LED strip. You want the connector with the arrow pointing toward it.

arrow

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.

diagram illustrating proper wiring connections

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:

WS2812 Breakout Hookup Guide

How to create a pixel string with the WS2812!

Das Blinken Top Hat

A top hat decked out with LED strips makes for a heck of a wedding gift.

SparkFun LED Array (8x7) Hookup Guide

Getting started with the Charlieplexed 8x7 LED array.

Cherry MX Switch Breakout Hookup Guide

How to assemble and use the Cherry MX Switch Breakout, allowing you to turn a matrix of mechanical switches into a full-size keyboard!

learn.sparkfun.com |CC BY-SA 3.0 | SparkFun Electronics | Niwot, Colorado


Viewing all articles
Browse latest Browse all 1123

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>