Introduction: RGB LED Light Fader
I wanted something really cool to put on my desk at work. I have seen various LED projects out on the web, but I wanted something small and compact that I could power with the USB port on my computer.
I also did not want just a bare LED bulb projecting the light, I wanted something that could be visible and had a lot of surface area.
I almost did not document this project as it was so simple, but everyone who saw it at work thought it was so cool, I decided to create this step by step so everyone could create this project.
I was having a hard time finding something that would reflect the LED light. One day I went to the grocery store and just happend to be walking down one of the isles and the night lights just jumped out at me. What a cool idea, I would use parts of the night light to construct the RGB LED Light Fader.
Here is a list of parts that you will need:
Radio shack project case
AC powered night light
USB cable that you do not need anymore (you are going to cut in in half)
ATTiny 2313 microcontroller
20 pin DIP socket (DIP = Dual inline package)
RGB LED, purchase several, as they are very cool to have around)
100 ohm, 1/4 watt resistor
2 69 ohm, 1/4 watt resistor
Some very small gage wire, 22 gage or smaller (larger the number, smaller the wire)
AVR programmer, ( I have several, but the USBtinyISP Kit v2.0 is one of my favorite)
Small Development board with a ISP header for programming. ($7.00 - $10.00, buy six pin header add-on)
Access to either WinAVR (if you have Windows, or Eclipse, with the AVR plugin if you have Mac or Linux)
Your bigest expense is going to be the AVR programmer, but you can use this over and over.
(Around $22.00, check out either LadaAda's web site, if you are on the east coast, or Evil Mad Scientist Labs, if you are on the
Lets start building, shall we.
Step 1: Cutting Up the Night Light
Here is an image of the night light that I purchased. We are going to perform some surgery on this night light so, after cutting it open, do not plug the night light in the the AC.
*** Safety waring ahead ***
It only takes about 100 milliamps to ruin your day, so just think what 15 amps can do to you.
Sorry I have got to do these warnings, for your and my safety
*** End of safety warning for now ***
Use a sharp x-acto knife, or an old soldering iron to remove the plastic around the light. We are interested in the small section of plastic that holds the clear reflector, I purchased two night lights, just in case I removed too much plastic or destroyed the plastic holder.
Please refer to the second image to see what I am talking about.
In the image you are interested in the black cutout, After removing this section I sanded the piece and painted it satin black to match the Radio Shack project case.
Save the circuit board from the AC circuit, as there are some good parts that you can use later. Also study the circuit, as this is an example of how you can take 120v/220v AC voltage and convert it to around 5 volts DC current.
Lets design our circuit.
Step 2: Circuit Design
Let's design our circuit. Even though this circuit is simple we have to be careful of a few items so we will not damage the LED, the USB port on your computer or burn out the ATTiny 2313 microcontroller.
If we look at the specifications on the ATTiny 2313 we discover that each port can only handle 40 milliamps, not a lot of current.
Voltage requirements are 2.7 - 5.5 volts.
If we do a little digging on our computer's USB port (1.x and 2.0) , we now know, the voltgage limitations are 4.75 volts - 5.25 volts
and current draw has to be limited to 500 milliamps.
There are two different types of RGB LED's, common anode or common cathode. I purchased the common anode RGB LED's.
anode is (+) positive, cathode is (-) negative
Here is the specifications.
Things are starting to fall into place. We know that the microcontroller and the USB ports have to operate at around 5 volts.
The microcontroller itself can draw a maximum of 200 milliamps and each port can draw a maximum of 40 milliamps, so the USB port can supply the voltage and current that we need.
So now the only thing we need to figure out is the requirements of the RBG LED.
Check out the link and the included image:
Lets look at the specifications on the RGB LED.
Notice the forward current and current voltage for each color.
We are in luck the Continuous forward current is 30 milliamps. as long as we stay below the 40 milliamp range for each microcontroller port we are fine.
Here is the tricky part, Notice that the forward voltage for each color is different.
So how can we balance this different in voltage requirements for each color.
No I am not going to make you do any math.
We are going to use one of the most used formulas that you should learn in electronics. Ohms law.
You study it on your own, we are going to cheat and use the internet.
Type in the following web address in your browser:
Don't you just love the web. Here is a LED current calculator
Type in our source voltage of 5 volts
Type in our forward voltage for the red LED, 2.1 volts
Type in our forward current of 30 milliamps
Now comes the hard part. Push the Find R push button.
Write this value down, 100 ohms for the red LED
Do the same thing for the the green LED.
5 volts, 3.1 and 30 milliamps.
Press the Find R push button
We need not do this again for the blue LED as 3.0 and 3.1 are way too close to each other.
Wow, we are now done with our design. Every part of the circuit has now been analyzed and we have proven
that our circuit components are safe to work with each other.
Lets now lay out the circuit and build the circuit board.
Step 3: Building the Circuit
I laid out the circuit, using Eagle software, download a copy, the lite version is free, Sparkfun has a great tutorial on how to use the Eagle software.
Refer to the image of the Eagle Circuit of the finished RGB LED circuit.
Notice the pins on the ATTiny 2313, we are using pin 20 for our voltage source of 5 volts coming from the USB cable (red lead)
We are using pin 10 for the ground source, the black lead on the USB cable.
Remember our resistor calculations, notice our 100 ohm and two 69 ohm resistor connections to the RGB LED.
We are using the B port, pins 12, 13, and 14.
Make sure that you double check these pins. When we write the program we will be using the same port pins.
If you use different pins your program will not work.
It might be wise to build this circuit on a bread board in order to test out the circuit and program.
Once everything is working, then transfer the circuit to a solder bread board and solder the components to the board for a more permanent installation.
Step 4: Breadboarding
I am going to assume you are going to built the circuit on a bread board.
(If you don't, there is a good chance you might damage some parts or have to un-solder and re-solder your mistakes)
Notice the RGB LED carefully, On on side of the LED there is a flat spot, This is your reference point on which way the pins are to be wired. With the flat spot on your left, the longest pin is second from the left. This is your common pin. The red LED lead is the left most lead, then the common lead, the blue lead then the green lead. When you wire up the LED please be careful to follow these guidelines.
Mount the RGB LED on the breadboard and attach the resistors to each of the leads as indicated on the schematic. No resistor on the common anode.
Attach a wire to the common anode and attach your power supply or battery pack to the anode wire.
Now with the ground wire to each lead of the resistor, notice the color change on the RBG.
See the attached images.
Wire up the rest of the circuit.
Make sure you understand the ATTiny 2313 pin locations. Get your ATTiny 2313, Find the 1/2 circle indentation at one end of the chip. Make sure you count your pins from this as your reference position.
Check the attached image of the ATTiny 2313 pinouts:
The pins we are concerned about are:
Pin 10, ground
Pin 20, 5 volt voltage source
Pin 12, Red LED pin
Pin 13, Blue LED pin
Pin 14, Green LED Pin
Make sure you wire up the common LED pin to you voltage source.
Please refer to the attached image of the finished breadboard:
Step 5: Getting Ready to Program the Chip
Seriously this step will take some time to setup. You are going to have to install some software on your computer and configure your environment for programming your chip.
The steps you take on this step will depend on what type of computer you have as well as what chip programmer you purchased.
Follow the following tutorial at LadaAda's web site:
When it comes time to write the program, you can insert the code that I have included in the tutorial.
Mac or Linux Computer
There are two methods to follow.
You can also use LadyAda's web site and follow the instructions for either Mac or Linux
My solution is as follows:
I program on a Mac and use the following software:
Download and install the CrossPack software
Install Eclipse IDE for C/C++ Developers (includes Incubating components)
Install the AVR plugin for Eclipse and configure Eclipse for your programmer
Since I use USBtinyISP v2.0, you would select this programmer.
Go slow and read all of the instructions. Once you do this a few times, it gets very easy.
Here is an image of the Developer board and USPtinyISP that I use:
When you program your chip, you place the chip on the development board, attach the six pin header jumper to the six pin ISP header as show in the next image. You then plug in your USB cable from the USBtinyISP programmer to your computer.
Follow the instructions to write the program to the microcontroller.
Remove the chip from the development board and install it into chip on your bread board for final testing.
Once you test your circuit and test your program you can build the circuit on your solder bread board.
Build the circuit with the ATTiny 2313 not installed, Install the chip socket as part of your build process.
After the circuit is finished, then add the programmed chip to the chip socket.
Step 6: Build the Circuit
Transfer the circuit from the breadboard a section at a time. As indicated before, install the chip socket without the microcontroller while you solder the circuit. Add the chip as the last step.
Pay special consideration of the height of the LED as it sticks out from the top of the case. You must measure that the height of the LED is at the correct height so when you install the project case lid and the reflector holder the LED sits at the correct height to fit into the clear reflector.
Once the board is finished install the board into your project case.
Drill a hole into the project case for your USB cable. Run the cable through this hole and solder the red and black lead to the locations as indicated on the Eagle schematic.
You will have to drill holes in your circuit board to match the holes in the project case. You can do this step before you start soldering when the board does not contain any parts.
Once the board is finished and you have soldered the USB wires to the board. Mount the board to the project case.
You can now hot glue the USB cable to the project case, so you do not pull the wires from the circuit board during normal use.
You can now screw the circuit board down to the project case.
We can now prepare the project lid.
Step 7: Prepare the Project Case Lid
In order to cut the slot in the project case lid, you must do a bit of measuring to make sure the LED is positioned correctly.
Back when you built the solder circuit board you made sure that the LED sat at the correct height. You can now use this position to cut the slot to properly fit the LED.
I have a drill press so it was easy to drill several hole and use a file to smooth the edges. If you do not have a drill press, you can use a hand drill or an old soldering iron to melt the slot into the lid.
I sanded the clear reflector holder and painted it satin black to match the project case. I also painted the project case screws to also match the project case.
Finish putting together the case, lid and reflector and take your RGB LED holder for a test spin.
You can see a finished video of my RGB LED Fader working below. The colors are much brighter in person than in the video.
Scroll down to the post about the RGB LED fader and click on the video.
Step 8: Code
I did not create this code, I found it out on the web. I cannot find the post to give credit to the developer of this code. But it is written well and works nicely:
Step 9: Video
I added a video to this page.
Participated in the
Make It Glow Challenge