Introduction: Arduino Controlled Positional RGB LED Christmas Tree
In this Instructable we'll be creating a programmable RGB LED Christmas Tree and building the (X,Y) positions of the lights into the Arduino such that we can create different patterns both animated and static. I'd recommend this to anyone who has micro controller or electrical experience as it is a really impressive effect without much time to build up, and is much more affordable and capable then color changing systems you can purchase in retail stores. Even after creating the system and putting it into motion it is fun to add new patterns and color combinations to the tree. In my case the tree will cycle color patterns every minute.
Beyond that I've tied it into a Raspberry Pi sequencer I developed so that the Arduino can accept commands via the serial connection and have dedicated control the RGB pixels to synchronize lights to music. The attached video shows this combined system.
If you like the Instructable, I'd love you vote as I've entered into the contest, thanks and enjoy the instructions!
Step 1: Materials
The following is the list of materials:
- WS 2811 LED Pixel String 12mm 5V
- Can be found on Amazon by several sellers, roughly $20 per 50 pixels
- Typically each end of a string contains a hookup to another subsequent string, allowing for longer string
- This instructable is focused on the method used to plot the light patterns, so if you are familar or have on hand a programmable LED string with a different protocol (WS2801 for example) then adjust the software and wiring as appropriate
- 5V DC Power Supply capable of driving the LED Pixels.
- Need to make sure the power supply can generate the amperage needed to power the LEDs. Typically the LED seller makes a claim on the power supply needed to drive a single string. In my case I picked up one that provided alot more amps than I needed. Measured about 2 amps but I bought this for 8 amps... Amazon
- Arduino - Any version would work, but I used the standard Arduino Uno
- Black Acrylic Paint
- Electrical Tape
- Optional: Additional JST connectors
- Most WS2811 strands have JST connectors at the ends. Regardless of the type of WS2811 connector, it would be preferable to be able to have the Arduino connect to the strand via a pluggable connector instead of having to cut the end of a WS2811 strand to connect.
Step 2: Testing Your Lights Before Usage
It's always a good idea to test the lights to make sure they're functioning before putting any effort into them. There are several good tutorials on how to wire a WS2811 strand to an Arduino.
Identify the +5V, GND, Data lines on your WS2811 strands. On mine it was:
- Red = +5V
- Blue = GND
- White = Data
Thus the hookup is:
- Red is connected to Power Supply Positive +5V
- Blue is connected to Power Supply Ground and Arduino Ground
- White is connected to Pin 6 of the Arduino (simply because that's the pin my code uses)
I've shown the hookup in the attached picture.
Install the popular WS2811 Arduino library from AdaFruit. Instructions are available at the website linked.
Modify the attached test.c code with the length of your particular strand via #define LED_COUNT and load/run the program on the Arduino. What you should notice is the light go from Red to Green to Blue to White for 5 seconds each. This ensures that all three LEDs inside each pixel (Red, Green,Blue) are functioning properly.
Step 3: Assessing the Voltage Drop
Each LED "Pixel" and subsequent wiring to the next LED will cause some amount of voltage drop. So at the end of your 50 LED strand the +5V that is being put out by the power supply will have dropped by some noticeable amount, for example a drop to 4.7V. This means the subsequent strand being plugged in will start with a 4.7V VCC and drop it down even further for the next strand.
The result is that each subsequent LED will be a little dimmer than the one before it.
(NOTE: Voltage Drop is a different issue than having a power supply putting out enough amps)
This will eventually bottom out around the +3.3V range, at which point the IC chip servicing the WS2811 protocol won't function properly anymore.
Your particular situation will depend on the amount of LEDs you are driving. These RGB LED work by having three LEDs, green,red,blue, in each "Pixel". Since white is a combination of full green+red+blue that means a strand colored entirely red will drop less voltage than a strand colored entirely white.
When running the test program do you notice a visible dimming towards the end of the strand? If you notice it, do you think it's acceptable? If not you will need to wire the +5V of the Power Supply to additional points on the strand.
In my situation I did notice an unacceptable dimming at the end of a 200 count (4 x 50 LED strand) run. What I did was supply power at both ends of the 200 count run, thus making the 100th LED the dimmest in the strand (instead of the 200th). The dimming was still noticable at the 100th LED when all white was being tested, but it was acceptable, and allowed for a simpler loop pattern when hanging the lights on the tree. The attached picture shows that the 5V power supply could be connected to the two ends at the bottom of tree, resulting in the top most LEDs of Strand 2 & 3 by the upper star being the dimmest. The alternative would have been to run another 5V and GND line up the tree and connect into the junction of strand 2 and 3.
Step 4: Coloring the RGB Strip
Normal Christmas lights are colored a deep green so that the wires blend into the tree, but likely your LED string is colored to help identify the wiring. To avoid the white/blue/red wire combo and IC plastic housing from being so noticeable I took black acrylic paint and painted the wire insulation. Hanging the strand from a height helps in being able to coat the entire strand in one sitting.
I cut small strips of black electrical and wrapped them around the WS2811 IC housing since painting the plastic housing would be more time consuming and the tape produced clean lines at about 10 seconds per LED
This step did take some time to do a good job at covering up the majority of the original wire insulation coloring, but the result was a professional looking LED string that doesn't draw any attention to itself on the tree.
Step 5: Hang Lights, Determine Positions
Hang the lights on the tree, and we need to calculate each pixels X and Y location to embed into the code.
To do this use the attached version of the xmas.c code and uncomment the first section of the Arduino loop( ) which lights each segment of 10 lights. You'll want to extend this section if you have beyond 50 LEDs with a simple copy/paste. Also remember to alter the #define LED_COUNT as in the previous step to match your LED count
In the attached video I took the grid image and overlaid it on top of the tree lighting in a Video Editor to allow me to get each of the 200 positions. Be sure to try and get grid column 1 and row 1 overlaid such that the lower left most LED light is at position 1,1. This is done so that the Arduino program can easily determine the middle of the tree in both the X and Y directions.
Watching the video and entering in X,Y pairs into xmas.c is a manual process, and 200 lights sounds daunting, but surprisingly this didn't take much time to record all LEDs. I'd estimate at 15-20 minutes to derive (X,Y) positions for 200 lights.
In lieu of a Video Editor you could take the video with a cell phone and then draw or print your own grid on paper to physically place on the cell phone/tablet/computer monitor while you play back the video.
To help isolate the 10 pixel segment being walked over, and entire 10 light segment is first lit in the following pattern:
Green Light 10 pixel strand = +10
White Light 10 pixel strand = +1
Thus a Green Light Flash followed by 4 White Light Flashes would be = 10 + 4 = 14th set of 10
As you calculate values, place them in the Positions array in the Arduino code.
Step 6: Running and Modifying the Code
The attached xmas.c file (same as previous step) is an example for the code needed to cycle through all different patterns. A run of this program is depicted in the attached video. From here you can modify this code to generate your own patterns and logic. The code is easy to understand and extend.
The other attached xmas_serial.c file is setup if you want the Arduino to be commanded via a serial line from another system. In my case a Raspberry Pi is used to drive the Arduino's control of the WS2811s and the Arduino is connected to the USB port of the Raspberry Pi. In this case the code comments indicate what commands are accepted via the serial line.
As an example pushing: chr(65) & chr(200) & chr(100) & chr(50) means that the first byte defines the command type A=Solid Colored Tree. The next three bytes 200,100,50 represent the Green,Red,Blue values from 0 -255.
That's it, a fairly straightforward build of applying the Arduino and a WS2811 set to a Christmas Tree to allow for any number of different color setups. I believe it's a great project relative to the price and capabilities of color changing lights available for purchase at stores, and that it is a nice stepping stone to more complicated LED interactions for future projects.