Introduction: Demystifying 4 Pin RGB LEDS (Radio Shack 276-0028)

Picture of 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

Picture of 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

Picture of 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!

Picture of 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!

Picture of 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

As you can see in the video, the LEDs cycle through their three colors into blends and finally into a 'all on' setting.   Sadly my iphone butchered the effect, but you should be able to get an idea of the way this works. 

I've included my source code and you are certainly welcome to use it in your own experiments.

Comments

bazbsg (author)2017-08-14

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.

DavidB552 (author)2016-12-08

how bright are these im hoping to use a cluster of them for a torch or lamp

SamuelP32 (author)2015-12-16

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

JinxKittie Cosplay (author)2015-08-17

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!

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.

Mark Collins (author)2015-03-21

Well who knows electronics and does'nt have an Arduino UNO.......... xD
I have mine..

CarterBond (author)2014-11-30

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.

mhermark made it! (author)2014-07-20

VERY helpful! I was having trouble with the tutorial from AdaFruit on controlling RGB LEDs and the information here was VERY helpful.

I think it is important to note that adding resistors to the system can have an impact on what color results on the LED end. I put in the values for a bright orange-red but got something more on the blue-indigo side. When the resistors were removed, the color changed to what I intended.

Lonely Assassin (author)2012-12-14

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.

I was totally thinking the exact same thing with the exact same value for the resistor. That's freaky.

Pusurspirity (author)2013-11-01

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);
}
}

SamGammond (author)2012-12-19

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

mattmahn (author)2012-07-01

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

adammary (author)2012-04-13

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?

Dain Unicorn (author)adammary2012-04-14

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);

CheesePatrol (author)2012-03-20

Thanks! This came in very handy on a project I'm working on

facklere (author)2012-02-25

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?

mpilchfamily (author)2012-02-21

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. 

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.

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

pcooper2 (author)mpilchfamily2012-02-22

You can also reverse the logic by using external inverting Darlington pair drivers in common-emitter configuration. That way, the Arduino code doesn't need to be changed, and the external drivers can be easily replaced in case of electrical damage, without risking the microprocessor chip.

Dain Unicorn (author)pcooper22012-02-22

In a production piece I would most assuredly like a level or two of safety between the micro controller and the business end of things. I'll look into external inverting Darlington pair drivers, as I have an upcoming project that they may prove useful for.

Thank you

matt.e.jenkins (author)2012-02-22

I wish i had this a while ago. I used one in a project and it was tricky figuring it out. Thanks for this.

Your welcome.

Knowledge shared is knowledge squared, knowledge hoarded is knowledge doom to be forgotten.

dwbechtel (author)2012-02-22

Actually, you supply power to the Common Anode and pull each Cathode to ground.

Dain Unicorn (author)dwbechtel2012-02-22

You are correct, and that is what happens, I simply stated it a different way.

maxhirez (author)2012-02-22

Thanks Dain! I got a load of these in an eBay lot and was starting to wonder if they'd ever have a use on my workbench other than sacrificial lambs...

pcooper2 (author)2012-02-21

The lack of proper documentation is a RadioShack hallmark; it has been so for decades. If the package includes the manufacturer's name and part number, one is well advised to go to the manufacturer's Web site and get a PDF copy of the specification sheet, which will include a package diagram with pinout, and often includes test circuits and even application hints. That's how electronics design engineers do it. It's much easier these days, as one doesn't need to get physical copies of the companies' data books.

Other good sources of PDF data sheets are industrial distributors, such as Digi-Key Corporation (www.digikey.com) in Thief River Falls, Minnesota and Mouser Electronics (www.mouser.com) in Mansfield, Texas. In the days of printed data books, the distributors would also supply all the documentation that engineers needed. Today they do it in the form of freely downloadable PDF files. As a matter of fact, as long as you're at the Digi-Key site, set up an account and place an order. RadioShack has a reputation of selling manufacturing seconds -- slightly out-of-spec parts that are considered "hobby grade". If you have a real, serious project, you might as well buy the real, in-spec parts from a reputable distributor. Digi-Key started out as a small outfit catering to the small buyer, and even though they've gotten big, they still fill small orders with no question. In my work as a design engineer in industry, I've often used them when I needed to quickly get parts for a prototype.

Dain Unicorn (author)pcooper22012-02-21

For what it is, A toy store that stocks components, Radio Shack isn't bad. Expect any more than that, and that's when you get disappointed. I guess I remember the days when Rafio Shack seemed to only hire people that knew which end of the tube went where. Yes, those days are long gone sadly.

I agree it's not the best resource, but many hobbists seem to start there. My 'day job' has me going there for my projects because as an Over-The-Road Trucker, waiting three plus weeks to get home for an order isn't always ideal.

Thank you for the links, I'll be sure to check them out.

About This Instructable

112,737views

126favorites

License:

Bio: I've been many things over the years, A television cameraman, a paperboy, a security guard, a Hotelier, a published author, a truck driver, a ... More »
More by Dain Unicorn:Demystifying 4 pin addressable RGB LEDSDemystifying 4 pin RGB LEDS (Radio Shack 276-0028)
Add instructable to: