Introduction: Demystifying 4 Pin RGB LEDS (Radio Shack 276-0028)
RGB LEDs are fairly useful in projects allowing for a wide range of color from a single unit. However they can be a pain in the neck to work with and they too often come with little or no documentation. I searched for some time to find a common resource on them and this Instructable is an attempt to pool the fruits of that search into one place.
But first, a word about diodes. What is a diode? It is the electronic equivalent of a one-way valve. They have a flow direction, and if inserted backwards do not work. They prevent the voltage from flowing through, except in the direction of their flow. The first diodes were used as rectifiers in decoding radio signal modulation. For more on the history of the Diode, your welcome to check them out on Wikipedia http://en.wikipedia.org/wiki/Diode
Whats that have to do with LEDs you ask? Well LEDs are by nature diodes. It is in their name -- Light Emitting Diode. This means that if you cross connect the Anode (+) and the Cathode (-), nothing happens and your circuit fails. Usually resulting in nothing more than an open circuit as voltage cannot flow. For more on the history of the Light Emitting Diode, or LED, you can go here on Wikipedia http://en.wikipedia.org/wiki/Light_emitting_diode
Four pin RGD LEDs are a little different. They share a common Anode, but three separate Cathodes, one for Red, one for Green, and one for Blue. If your not careful you can pass current through conflicting parts and cause a spectacular failure complete with a snap, a pop, a whiff of ozone, and plastic shrapnel flying all over your workspace.
This is usually caused by the omission of a current limiting resistor to the circuit (yes, I'm guilt of this). Incidentally, this sort of failure is not covered by Radio Shack's warranty.
The LED in this project was purchased at a local Radio Shack and has the following part number, 276-0028
Step 1: The Pinout
One of the most annoying part of these little gems is the lack of a pinout diagram that was useful.
While looking at the photo, you will notice that the four pins are three different lengths. Also there is a flat side of the housing on the left side. With the flat side to the left, as in the photo, the pins are: RED Cathode (medium length pin), Common Anode (longest pin), , BLUE Cathode (shortest length pin on the inside), and GREEN Cathode (shortest length pin on the outside). This is not how I would have designed the unit as I think it would be easier to keep up with it if were Red-Green-Blue, but that's logic for you.
A quick look at the datasheet screen-printed on the package indicates that the different Cathodes use different current levels. 2.0V to 2.6V max at 50ma for the Red, and 3.5V to 4.0V at 30ma for the Green and Blue. Its important to note this when calculating what resistor(s) are necessary for your project.
Step 2: Placement on a Breadboard
With four pins close together you need to make sure to place each pin in a different column on your breadboard. This will require slightly bending the legs to accomplish. You might want to use a precision screwdriver or toothpick or similar object to assist you in placeing the pins in the desired socket.
If your hooves are as large as mine, you may find it useful to use lateral jumpers to open up the area your working with.
Step 3: Resistence Is Not Futile, It Is Required!
One of the most common newbie mistakes with LEDs is simply hooking them up like a common lightbulb. I've seen people using button-cell batteries for this purpose to test LEDs and while it might work for a little while for that purpose its not a good thing, really.
LEDs do not tolerate variable voltage well. That means that if you apply too much voltage, they pop. That means if you apply too little voltage they don't work at all. The 'Goldilocks' zone is far more narrow than with a incandescent light bulb, and unlike the old trusty filament bulbs, you cannot control the intensity of the output with voltage, they either light up, or not. Let me say that again, YOU CANNOT CONTROL THE INTENSITY OF THE OUTPUT WITH VOLTAGE. In order to control intensity you must use a micro-controller capable of Pulse-Wave Modulation, or PWM. For this I am using an Arduino UNO, more on that in the next step.
You must have a resistor in the circuit to make sure everything works right. Now from the way I learned about these things when dinosaurs walked the earth and Microsoft was still on version 3.0 of Windows (running under 4.01 of MS-DOS no less), you would place the resistor between the voltage source and the LED. The LED Calculator for single LEDs shows this method, http://led.linear1.org/1led.wiz Its exceptionally useful, bookmark it... No really.
Wisdom being what it is you will occasionally find references to placing the resistor AFTER the LED. I have done both under test conditions and can attest that it too works. In fact the LED series parallel array wizard http://led.linear1.org/led.wiz shows this alternative method. If someone cares to enlighten me on why this works when it seems to violate the need for a resistor in the first place, I'll be happy to add their knowledge here.
Step 4: Must!... Retain!... Control!
Ok, don't go, I'll nix the Shatner voice...
After you have figured out what resistor(s) you need, you need a way to control how much light each of the three elements produce. I'm using an Arduino Uno for this, and a fairly simple wiring setup. I route Pin3 to the Green Cathode, pin6 to the Blue Cathode, pin9 to the Red Cathode, and pin11 to the Common Anode. There is a single 220 ohm resistor (which is overkill, but it was what I had at hand). Even though you can see two LEDs, they are wired in parallel so it would work just as well as with one.
I can pass a value between 0 and 255 to the analogWrite() function and it will fade the LED element to the desired level. If that scheme seems familiar, it should be as web-colors are expressed in decimal notation that way. The only major difference is that the scales are reversed. Passing a value of '0' to the LED turns it on at full intensity, while a value of '255' effectively turns it off completely. Due to the limits of PWM some combinations appear to flash or fluctuate, but plenty of combinations do work. Also since the elements are not matched for current drawn if the RED element will overpower the other two at any even setting. These limitations of my simple setup can be fixed by the use of a more complex design, such as the one by mpilchfamily in their instructable 6-button-RGB-controller
I found a schematic and sample code from fritzing.org. I hesitate to include this as I had difficulty getting it to work as desired. It does work however. The writer of that article also seems to mix up his terms when labeling the Anode and Cathodes, but shows the polarity correctly.
As you can see above, I don't pull the power from the far side of the Arduino, but from another digital pin (pin 11), so a single line of code needed to be added to the sample code to get it to work. Just add. "digitalWrite(11,HIGH);" to the top of the void loop() section and your off to the races. (I've included my sourcecode in the final step)
I should take a moment to point out a few things that had me going in circles. First and most off, there doesn't appear to be circuit leading to ground, this is in fact not true, it only appears that way. The 4 pin LED is controlled by stepping the PWM voltage to ground. The Arduino board itself becomes the path to ground. So you apply power to the Cathode and ground out (or not) the Anodes in order to get a certain amount of colored light, that's why the higher the number the dimmer the LED element.
Personally I wasn't happy with just random colors, and found the blending effect not at all what I was looking for so I started tweaking by reducing the range of the randomized number and adding base value modifiers so that I always had a certain level of one of the three elements going. By watching the serial monitor you can get an idea of the values needed for each color combination. This gives you a place to start looking for what you need for your project.
Step 5: Final Thoughts
I've included my source code and you are certainly welcome to use it in your own experiments.
Attachments

Participated in the
Arduino Challenge
29 Comments
5 years ago
I am having a lot of trouble with my 4-pin led and my breadboard with a Feather Huzzah. Basically, if I power the pin that is meant to be the ground (long one) and then move the ground to the other pins, I get my three colours, but I can't do it the other way. Ground the 2nd pin and then powering any or any combination of the three other pins results in no light. What am I doing wrong?
6 years ago
The preferred was to do this would be to connect the common anode to the 5V power supply and have separate resistors for each RGB cathode. As it is now the red LED has a lower forward voltage drop than the other and will prevent them from turning on at all. You are probably getting some color out of the other two only when the red is switched off during the off part of its PWM cycle. With separate resistors, each color will be controlled only by its own PWM and not influenced by the other colors' PWM. We don't know from the specifications shown how bright each color is as a function of current, so you may need some experimentation to pick the resistance values to get a balanced color. Blue is less bright than red and green so it probably needs a lower resistance to get a balanced brightness and red has a lower forward voltage so will need a higher resistance than green to again balance the brightness. Also keep in mind that the human eye is more sensitive to green than to red and blue. It may be three resistors versus one but the results will be well work the extra pennies spent.
6 years ago
how bright are these im hoping to use a cluster of them for a torch or lamp
7 years ago
How can I set it up withs pins on a ardiuno if the rbg is the ground of the led. Do I have to use transistors
8 years ago on Step 5
Could you cycle with only two of the Cathodes (blue and green)? Could this be achieved by just ignoring that red pin? I'm not sure about this and don't want to break what I've done in order to test!
Reply 8 years ago on Step 5
Sure, with this type of RGB LED you only need to connect the pins you need.
The code to control these units is flexible. You can simply keep the red pin at zero, and ignore in software too.
8 years ago on Step 3
Well who knows electronics and does'nt have an Arduino UNO.......... xD
I have mine..
8 years ago on Introduction
Hey. I need some help. I got a Arduino Mega today. I am trying this but I am having some trouble. The only color I get is green and it flashes. Any help and trouble shooting would be nice. Thanks.
10 years ago on Step 4
I'm kind of new to electronics, so I may be wrong, but I do have a theory. Could it be possible that the red is overpowering the blue and the green because of the common resistor serving all 3 colours rather than appropriate sized resistors for each? Because of the different forward voltages and currents (2.0V-2.6V@50mA Red/3.5V-4.0V@30mA Green and Blue) I believe you should add more resistance to the red. What if you were to add a resistor (I'd estimate around 22 ohms) between the output on the Arduino and the red leg of the LED? Let me know if you try this out and if it solves the problem. I'd be interested in knowing how far off I am.
Reply 9 years ago on Introduction
I was totally thinking the exact same thing with the exact same value for the resistor. That's freaky.
9 years ago on Step 5
Very nice writeup:) Helped me locate the different pins on my led:)
Your code looks cool too. I changed it a little for my needs however. Your code completely fades one color before it starts the next one so u get "black spots" in between colors. I wrote one that starts the next color before fading the first one so you get a smooth transition. Im a complete n00b tho so not sure if my code is clean but it works:)
__________
byte Led1 = 3;
byte Led2 = 5;
byte Led3 = 6;
int nextColor;
int firstFade = 1;
void setup() {
// put your setup code here, to run once:
pinMode (8, OUTPUT);
pinMode (Led1, OUTPUT);
pinMode (Led2, OUTPUT);
pinMode (Led3, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(8, HIGH);
analogWrite(Led1, 255);
analogWrite(Led2, 255);
analogWrite(Led3, 255);
if (firstFade == 1){
for(int fadeValue = 255 ; fadeValue >= 100; fadeValue -=1) {
analogWrite(Led1, fadeValue);
delay(20);
}
firstFade = 0;
}
for(int fadeValue = 100 ; fadeValue <= 255; fadeValue +=1) {
analogWrite(Led1, fadeValue);
nextColor=map(fadeValue, 100, 255, 255, 100);
analogWrite(Led2, nextColor);
delay(20);
}
for(int fadeValue = 100 ; fadeValue <= 255; fadeValue +=1) {
analogWrite(Led2, fadeValue);
nextColor=map(fadeValue, 100, 255, 255, 100);
analogWrite(Led3, nextColor);
delay(20);
}
for(int fadeValue = 100 ; fadeValue <= 255; fadeValue +=5) {
analogWrite(Led3, fadeValue);
nextColor=map(fadeValue, 100, 255, 255, 100);
analogWrite(Led1, nextColor);
delay(20);
}
}
10 years ago on Step 3
The resistor sets the total resistance in the circuit path. This is what determines the amount of current running through the circuit (simple Ohm's law -> V = I x R -> I = V / R).
Resistance of any diode from anode (+) to cathode (-) is essentially zero.
An example: 5 V across a 220 ohm resistor.
current = voltage / resistance -> I = 5 V / 220 ohms = 22.7 mA
So it doesn't matter where the resistor is in the circuit path; the total circuit resistance would be the same so the amount of current running through the LED is the same.
Now with no resistor in the path and just a voltage source connected to the LED.
current = voltage / resistance -> I = 5 V / 0 ohms = infinite amps
of course there's no infinite current, but your voltage source (battery etc.) will put out it's max current... so as he said... no resistor.. LED goes "pop"
Sam
11 years ago on Step 3
It works both ways because the current is dropped before it reaches the power source and LED again, completing the circuit.
Think of it as a Snake game, where the head is the first electron. The electron leaves the anode of the power source and flows through the LED not yet illuminating it because the circuit is incomplete. The "head" continues into the resistor which drops the current/voltage to a safe level for the entire [series] circuit; then continues to the anode of the power source, completing the circuit and illuminating the LED.
Disclaimer: I'm subscribing to the actual movements of electrons (from negative to positive), not conventional
11 years ago on Introduction
Hi,
Not all the pins must be connected to PWM pins right? I mean if I want to leave the red light on and vary just the blue and green light, i can just connect the pin corresponding to the red light to a non PWM-pin?
Reply 11 years ago on Introduction
No, if your happy with the output at full intensity, then by all means connect the Red Cathode to a digital pin and simply use digitalWrite(RedPin, HIGH);
11 years ago on Step 4
Thanks! This came in very handy on a project I'm working on
11 years ago on Step 3
My knowledge of electronics is extremely limited, so I could be completely wrong, but I believe the placement of a resistor after the LED works because it still limits the flow of current through the circuit. If the lead after the LED is disconnected, opening the circuit, the LED can not blow out because current is not flowing through the circuit. In the same way, if you limit the amount of current flowing after the LED, it will also limit the amount flowing through it. Again, could be totally wrong on this. Anyone know if it's right?
11 years ago on Introduction
You may want to reread and relabel everything. In your image you have the pins labeled wrong. The longest pin is your common Anode. Your last paragraph in step 1 then mixes up the Anode and Cathode again.
In your final hookup your using a single 220 ohm resistor on the Common Anode. While this works to keep the LED from burning out it doesn't balance your colors. As you mentioned the individual colors in the RGB have different forward voltages and current. I cover this in my 6 Button LED controller i posted a couple of weeks ago.
https://www.instructables.com/id/6-button-RGB-controller/
So if you want each color to have the same brightness you will need a different resistor for each of the Cathodes.This way when all 3 colors are full on you have the LED shining white. Otherwise your have a greenish blue hew to the light. That is why your blending effect looked a little off.
Reply 11 years ago on Introduction
Thank you!
I originally thought it was a common Cathode model, and started writing that way. When I discovered I was wrong, the instructable was almost finished and I thought I had fixed the inconsistencies. I've linked to you and your project in the 4th step because your right, designing a circuit with resistors to bring the voltage in line would help blend things better, but as you can see I tried to keep things at the simplest level and still demonstrate the LEDs abilities.
Reply 11 years ago on Introduction
I struggled with the same thing when i was working on my project a couple of years ago. Had a big discussion about it all on the Arduino Forums. At first i was using separate red, green and blue LEDs to make my sketch. I then went to Radio shack to get an RGB. I ran into all sorts of problems when i switch to the RGB. My sketch was originally controlling the LEDS through the Anode. So getting an RGB with common Anode forced me to reverse the logic of the code. So the complications of the LED change and my limited coding knowledge made things difficult. Here is the link to the thread.
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1263501476