Introduction: RainBoard - RGB LED Rainbow Fader
Runner Up in the
Make It Glow Challenge
Introducing the RainBoard: A simple RGB LED Rainbow fader using an Arduino Uno and a few simple components. Believe it or not, we will control 45-channels of RGB LEDs at 32 brightness levels using only 3 digital pins from the Arduino! How is this possible you ask? By using two magic concepts: Shift Registers, and Pulse-Width Modulation. Some of the schematics/images may seem daunting, but if all instructions are followed carefully, it should be easy to have this set up and running in less than 30 minutes (perfect for those that forgot to get that special someone a Christmas present this year!).
This is my entry into the Make it Glow Contest. And also my very first Instructable, I hope you like it!
Here's the schematic and the diagram of what we will be making.
Here's a video:
Step 1: Parts
Before we begin, here is a parts list of everything we will need for this Instructable as well as links to vendors where these items can be obtained. When designing this circuit I made sure to select common components that can be found just about anywhere that sells electronic parts. I found all of the items here on eBay, but many of the standard on-line electronics distributors (Digikey, Mouser, SparkFun etc.) should have these items in stock. I linked to SparkFun parts to make ordering easier.
2x RGB LED Strip - 30 LED/m 1m
We need these to make the pretty rainbow effect! One of the most crucial components as you can't make it glow if you don't have something to emit light. We need two because each strip will be cut into 10 sections and we need 15 sections total for our project. This will give us 5 sections as spares in case something goes wrong.
2x Break Away Headers - Straight
These are to make the RGB LED strips easy to plug straight into a standard breadboard. Those RGB LED strips need power and we're going to give it to 'em! We will be soldering these onto the RGB LED strips, and each strip has 4 connections. Since we will be making 15 of these sections, we need 60 pins total, and each purchase comes with 40 pins. This will give us 20 spare pins in case we break them in the wrong spot.
6-8x 74HC595 8-Bit Shift Registers
These are the meat and potatos of the project. In order to make such a large amount of wires connect to the Arduino, we need these shift registers to pass the information along to the RGB LED Strips. We only need six Shift Registers to make this work, but I always like to order extra. That way, in case something happens to one or two of them, we still have the parts to complete the project. Just make sure to be careful if you only order six.
6-8x ULN2803 DIP 8-Channel Darington Driver
These are one of my favorite electronic components. I'm sure lots of you are familiar with a standard NPN Transistor. The beauty of these is that they are comprised of 8 transistors built in but all of them have a common emitter. This makes them a great item to sink lots of high current (up to 50v @ 500ma!) LEDs that share a common anode. These will be the muscle of our project. Again, we only need six of these, but as all of us know, good ol' Murphy's Law can play a part in any project. It's good to have backups.
2x Basic Breadboard
Any electronics project needs a breadboard. If you don't have any of these, I would suggest buying some even if you don't complete this project. Even for the simplest of circuits these things are worlds easier to use than alligator clips. We need two because we are going to be pulling the rails off of one side on both of the breadboards. This will let us move them closer to each other, giving us 3 channels to work with.
1x Arduino Uno (or other similar model)
Ahhh, the Arduino, how I love thee. I could write a tome about how much I love this thing. I could write poems, love letters, Haiku's, and songs about this simple yet glorious device. This Instructable is long enough as is, so I will spare you all the
weirdnesss. We only need one of these as long as we are super careful with it. Be gentle to it and it will love you almost as much as you love it.
1x 12VDC Wall Adapter Power Supply
We need to power this puppy and something like this should do. I use a prototyping power supply (Around $200) so not everyone has access to one. One of these will work just fine as long as it's 12VDC, it's regulated, and has a 2.1mm center-positive barrel jack.
1x Any way to connect things together.
My personal favorite are simple jumper wires. I always seem to run out of these so order a few of them if you can. If not, simple 22 gauge solid-core wire and some wire-strippers will work like a charm (and much cheaper). I tend to use the jumper wires for straight and short connections and use 22 gauge wire to for the long, awkward connections. This will keep things nice and neat.
1x Soldering Iron
Any soldering iron will do, pick something around 30w if you can.
1x Third Hand (optional)
This isn't required, but will definitely help in step four!
Enough shopping, let's get to building!
Step 2: Theory
Before we dive in head-first, I thought I would explain a little bit of how this thing works. For those of you that want to get started, you can skip this section and come back later if you want to learn the theory.
For this project, I wanted to make a 15 RGB LED strip rainbow fader. This will be eventually mounted in a picture frame and mounted on the wall as a mood light (in a later Instructable). In order to change the color of each strip, we have to quickly increase/decrease the brightness of each LED's RGB channels. There are many ways to do this. The most efficient way to do this is through pulse-width modulation (PWM). That may sound like a big word, but it's actually quite an easy concept to understand. As with most LEDs, these RGB LED strips normally have two color options per channel: ON or OFF (kind of like that monitor on the Apple I back in elementary school). But what if we decided to quickly turn the LED on then off again, many times per second? Turns out that the human eye still sees the LED, but we don't see it turn on or off. It simply looks less bright. This is the basic concept of PWM. By turning it on and off again and at very fast rates, the human eye couldn't be the wiser in determining if the LED is on or off! It simply looks as if it fades between brightness levels.
If we made the first LED's red channel fade into it's green channel, it would look like it was fading from red, to orange, to yellow, to green. If we did this with its blue channel, soon we have every color of the rainbow, but we would only have it fade each color of the rainbow on one RGB LED Strip. Now what if we did this in synchronous with all of the RGB LED strips? That's where the Shift Registers come into play.
As all digital communications work with 1's and 0's (HIGH and LOW, or ON and OFF), we need a way to tell each of the wires to turn itself ON or OFF, and rather quickly. Luckily the shift register was designed for this purpose. Basically we tell the Arduino a string of 1's and 0's and it feeds them into the shift registers. When one shift register gets full, it passes the first 8 digits that was fed to it on to the next register, and so on until all 6 registers are told what to do. Think of it like a row of seats in a movie theater. When someone first enters the row, they go to the last seat until all of them are full. When new people want a seat, the first person that entered now stands up and leaves (to the next shift register). Everyone then moves over one chair and the new person can now sit down. This is similar to how a shift register works. We can talk to all of the RGB LED strips in this way.
But then how do we make this work off only 3 digital pins from the Arduino? Going back to the row of seats in a movie theater comparison, we know that we only need one cable to send 1's and 0's to the RGB LED strips (the line of people). But the shift registers need two more pins, one for the clock, and one for the latch pin. The clock pins is pretty self-explanatory. It's essentially a way to tell the shift register how quickly things are happening, much like the 16MHz clock tells the Arduino it's own timing. The latch pin plays a critical role with shift registers. It tells the shift register when we are ready to write to it, and when we are done writing to it. Without such a pin, data would constantly fly out the end of the rows, much like our poor movie patrons if someone decided to steam-plow through the aisle. This would be just as bad for our movie patrons as it would be for electronics. This pin keeps data in the register until we are ready to write to it.
But what about those ULN2803's? What the heck are those things for anyways? Well, unfortunately the RGB LEDs run on 12VDC power and the shift register works on 5VDC. To work around these limitations, we will feed 12VDC into the Arduino, and access it through its 'Vin' pin to power the RGB LED's, and use the shift registers to control the ULN2803's (which are like 8 NPN Darlington transistors crammed into one glorious chip of awesomeness!). The beauty of these are that they have a common emitter, which means if we plug in an RGB LED that has a common anode and plug the anode to +12VDC and plug each cathode into the collectors of the ULN2803, then when we switch them on with the transistors it closes the circuit and grounds the cathodes, making the LED turn on. (*phew* that was a long sentence.)
Enough chit chat, we've got a RainBoard to make!
Before we get too far (last time, I promise!), I want to briefly discuss DIP packaging for those of you that are new to electronics. DIP packaging, or Dual In-Line Packaging, is a simple building standard developed for small electronics chips. The important thing to note here is that almost all chips built around this standard have the same pin configuration. While looking at the chip from the top (so you can see the numbers), you will see either a dot, notch, or a curved groove on the chip. Turn this so that it is at the top (12 o'clock). The first pin on the top-left is pin #1. Moving down the left side, there is pin #2, pin #3, etc. When you get to the bottom you now count the right side, but this time you count from the bottom up. They are kind of numbered counter-clockwise in this sense. For more clarity, see the image.
Time to get building!
Plug in your soldering iron to let it heat up while we prepare our components.
Each of the RGB LED strips come in a 1 meter length but every 10cm or so you will notice that you can cut the LED strip into segments and use it as a mini-strip. We will need to do this to make individual segments for our RainBoard. Cut each of the segments with a pair of medium sized wire cutters and it should separate just fine. Then we need to strip back the weather-proofing. A simple box cutter should do just fine, just make sure to remove enough to expose the leads of the LED strip (some strips do not have this weather-proofing, mine didn't). The next step is to break the pin headers into 4-piece segments to solder onto the RGB strip so we can insert them into our breadboard later. This is where the soldering iron comes into the play. Using your third hand (or alligator clips if you don't have one), clip the pin headers to the strip and solder the pins one by one onto the board. Make sure that when you do this that you solder the proper side! See image. Once all of this is done we are ready to move onto step 5.
Now we need to prepare our breadboards. What we need to do is remove the rails from either side of the breadboard so we can cram them together. If your breadboards came with a sponge backing, just cut it with a box cutter and it will separate easily. Now we will remove the railing from the left side of one breadboard, and the right side of the other board. Mate the two together where we previously removed the rails and we now have another channel where we can insert DIP packages. See images.
Now we are finally ready to start wiring! Insert the DIP chips (the 74HC595's and ULN2803's) into the breadboard. Simply insert them as show in the images, being sure to note the position of the notches on the chips (One will be "upside-down" from the other one). See images.
Now we will provide power to our shift registers. We will connect pins 16 and 10 to power, and 13 to ground. See images.
Now connect pin 8 of the shift registers to ground. You can wire them straight to ground (like the diagram) or connect them to pin 13 like I did in the photo. See images.
Now we need to connect pin 15 of the shift register to pin 8 of the ULN2803's. See images.
Now we need to give our ULN2803's somewhere to sink the current of the LED's to. Connect pin 9 of the ULN2803's to ground. Again you can wire them straight to ground like the diagram, or connect them to pin 13 of the shift registers like I did. Either way, it'll get where to where it needs to.
Note: The bottom-most ULN2803 doesn't show that its pin 9 is connected to ground. Make sure you connect this one as well to ground!
Time to plug in the LED' strips we soldered together back in step 4. Make sure that the pin order is correct. If you are looking at the photo, I have them plugged in this order, from left to right: +12v, Green, Red, Blue.
Now to power each of the +12v pins of the LED strips to the second power rail on the back of the breadboard. If you get lost, just flip the board back over and the RGB LED strips have the pins conveniently labeled.
This step is the easiest, while at the same time easiest to mess up. We will be connecting all of the LED's to the ULN2803's. Make sure that you don't accidentally connect any of the +12v pins of the LED's to the ULN2803's, or that you accidentally connect pin 10 of the ULN2803's to anything as they should be left open. Just start with the far-right ULN2803 and plug the pins in from right to left. See images.
Now we will connect the shift registers together. Starting with the far right, plug pin 9 to pin 14 of the shift register to its left. See images.
Now for another step that is simple to do yet easy to mess up. We are going to connect pin 12 from the far left register into pin 12 of the register its right. We will be doing this with all the shift registers. We are piggy-backing signal in a weird sense. Do the same with all pin 11's of the registers. If you get lost, see the images.
Now for some power. Connect the positive power rail that the RGB LED's are plugged into to the 'Vin' pin of the Arduino. Since we will be powering the Arduino with a +12VDC power source, this will give us access to the +12VDC from the Arduino's 'Vin' pin. After that, connect the other positive power rail to the '5V' pin of the Arduino, and it's adjacent negative power rail to the 'GND' pin of the Arduino. See images.
Finally we will connect the Arduino to the first register (the very far-right one, or the bottom one in the schematic/diagram). Connect digital pin 8 of the Arduino to pin 12 of the shift register. Then connect pin 11 of the Arduino to pin 14 of the shift register. Lastly, connect pin 13 of the Arduino to pin 11 of the shift register. See images if you get lost.
74HC595 (SCLK) Pin 11 -> Pin 13 (D13, SCK) of the Arduino
74HC595 (RCLK) Pin 12 -> Pin 8 (D8, ICP1) of the Arduino
74HC595 (SER) Pin 14 -> Pin 11 (PWM, MOSI) of the Arduino
Note: The bottom-most shift register doesn't show that it is the one connected on the Arduino in the illustration. Make sure this is the one connected to the Arduino!
Now to program the Arduino. The RainBoard's sketch is based around the ShiftPWM Library by Elco Jacobs. I want to take this time to thank him for all the help he's given to the Arduino community. Keep up the great work!
Link to ShiftPWM: http://code.google.com/p/shiftpwm/downloads/detail?name=ShiftPWM_v1_03.zip
Link to RainBoard Code: http://code.google.com/p/rainboard/downloads/list
1) Download ShiftPWM library from the above link.
2) Extract into the library folder of the Arduino's directory on your hard drive.
3) Download the RainBoard Code.
4) Extract into the Examples folder of the ShiftPWM folder.
5) Plug Arduino to computer with a USB Cable.
6) Open Arduino Environment.
7) Select File > Examples > ShiftPWM > RainBoard
8) Click "Upload".
9) Once uploading is finished, unplug USB cable from the Arduino.
I hope that through this Instructable you have learned a lot about Shift Registers, Pulse-Width Modulation, RGB LED's, and the wonderful capabilities of the Arduino!
Snubs made it!
We have a be nice policy.
Please be positive and constructive.