Common Annode RGB LED: Possible solution?

I picked up an RGB LED, but at the time I didn't realize I needed a common cathode type to do anything useful with it. However, I think I may have found a way to use it with Arduino PWM pins. Maybe. I just need an electronics guru to take a look at this idea so I don't fry my controller. I have simulated this circuit and electronically it should work, but I have reason to believe it could damage the chip.

        R1       RED   PWM D1
+5---/\/\/\---+-->-----+--->-+
               |              |
               |GREEN  PMW D2 |
               +-->-----+--->-+
               |              |
               | BLUE  PMW D3 |
               +-->-----+--->-+----GND

The PWM outputs need to be inverted for this so that full duty load means no brightness and vice versa. Even after watching the simulation, I don't want to trust my Arduino to my self-taught electronics knowledge. I just got it today, I'm not ready to burn it out just yet.

that drawing looks like D1, D2, and D3 are all connected together and also connected to Ground. That will not work.

I'm still learning Arduino myself, but have a fair bit of experience in electronic hardware. Can't quite follow your drawing but this is my suggestion.

Connect a resistor of 330 ohms or a bit higher between each LED and the Arduino pin it connects to. Leave out R1. Unless I've completely misunderstood what you're doing, this should save things from frying. The brightness of the LEDs may not be right yet but this should give you an idea if your sketch will work.

Sorry. I should have said replace R1 with a piece of wire. You need that end of the LEDs still connected to 5v.

I needed a common cathode type to do anything useful with it.

No you don't.

  1. Connect the anode to 5V.

  2. Connect a resistor (between 150 and 330R) to the red cathode.

  3. Connect the other end of the resistor to pin 3.

  4. Connect a resistor (between 150 and 330R) to the green cathode.

  5. Connect the other end of the resistor to pin 5.

  6. Connect a resistor (between 150 and 330R) to the blue cathode.

  7. Connect the other end of the resistor to pin 6.

Now in your code analogWrite(3,255); will turn on the red part of the LED.
analogWrite(3,val); will set the brightens of the red led to the contents of the variable var with 0 being off and 255 being full on.

Have fun.

Grumpy_Mike typed faster than I did, but I already had a photo for exactly this.

One correction, writing a lower value to the PWM will make the LED burn brighter, writing a higher value to the PWM will make the LED glow dimmer. The value 0 is fully bright, the value 255 is fully off. This is because we're draining current as a cathode.

.           RED      R1     PWM D3
. +5----+---->-----/\/\/\-----+
.       |           220o
.       |
.       |
.       |   GRN      R2     PWM D5
.       +---->-----/\/\/\-----+
.       |           220o
.       |
.       |
.       |   BLU      R3     PWM D6
.       +---->-----/\/\/\-----+
.              100o

This is because we're draining current as a cathode.

Spot on Halley your right.

Oh. I didn't realize there was such an easy solution. In fact, I bet this is a pretty common question here. (Hence the competition for first? And the pretty pictre!) I guess the thread I was reading earlier had a much narrower scope. Like common anode with a specific driver.

Is there a reason for the different resistor values? Probably just a balancing thing, huh?

Do'h! Even with my limited electronics knowledge, I now see how this solution is just simpler (and working) way of doing what I had in mind. When the PWM is on full, it's 5 volts and so is the 5v. Same potential on either side, nothing happens. Right.

One more question: My LED seems to only want to turn on one element at once. Isn't that stupid? What's the point of an RGB LED if you can't mix the colors? (I could be wrong, because I tested this with a battery and some wires, I didn't have any suitable switches or pots.) So anyways, is there a way I can un-synchronize the three PWM to at least get 1/3 duty cycle out of each PWM, adding up to full duty cycle over all?

Thanks for helping, folks!

(Siderant: This is what I love about uC development. Finding a solution to a single problem jumps from electrical engineering to programming in a flash.)

My LED seems to only want to turn on one element at once. Isn't that stupid?

Looks like you'll need to show us exactly what RGB LED package you have. If there's four leads coming out, it's probably a wiring/experimental error on your part, unless you have something particularly exotic.

My LED seems to only want to turn on one element at once.

It will do that if you only have one resistor in the anode and not a separate resistor in each cathode. My moneys on that.

halley: That very well could be. It is a regular 5mm package, clear diffused, with four inline leads. The first is medium length, the second is long (the anode), and the other two are shorter. I bought it from Radio Shack for way too much.

Grumpy_Mike: This test was done by touching wires to the leads. So I touch the cathode wire to the red lead, I get red. Touch it to green, I get green. But touch it to both and I get red. Maybe what you're saying is still valid, but I don't quite see how it could be.

P.S. Does anyone know how to get into my settings? All the times are in GMT, I'm in PST. I can usually handle web apps, but somehow I can't find this.

Maybe what you're saying is still valid, but I don't quite see how it could be

EXACTLY that is what you are doing wrong.

When an LED is on there is a volt drop across it. Roughly 1.8V for a red LED and 2.0V for a green one. If they are both connected together the red one comes on first and so the green one never gets enough voltage to turn on.

Connecting an LED directly to a battery without a resistor is a very good way of destroying the LED.

Right! I think I saw something about that on wikipedia:

And yeah, I was using a resistor with the battery. I learned the hard way to use resistors with LEDs when I tested some rather expensive ($2-3) LEDs, a blue and a white, with a wall wart.
"Let's see, does this work? It did, but now it doesn't." -Me
Brilliant. In both the ironic sense referring to my decision and in the literal sense for the fraction of a second before it burned out. The question is, why did it take me two to figure that out? Those were the only two I had!

Well that's good to know that it isn't a mostly useless RGB. I'll try it with my Arduino when I get home.

The first thing many people learn is that these two circuits are identical:

+5V <--------------//////--------------|<|-----------------||| GND

+5V <-----------------|<|---------------//////-------------||| GND

However, this is not true if there are any forks in the road, branches between multiple paths, involved. It's like driving your car: if a street has a "narrow bridge" and a "stop sign," it doesn't change your overall time of travel which order they occur. But if other cars can merge into your lane of travel at the stop sign, but before the bridge, this will slow you down. If they join your road after the bridge, it's got no effect on your overall speed.

A resistor limits current. (And a plain old wire is just a very-low-resistance resistor.) Current is basically a constant for any single path through the circuit (from a junction to a junction).

If you put your resistor on the common anode, and you have multiple cathodes held low, then the current has a choice of which cathode to go, and it will try to go through just one of them: the one which can pass the most current. When that line can't pass any more current, ONLY then will any remaining current start going down the next-most-favorable path. Traffic jam!

If you put your resistors on the individual cathodes, then all individual paths are poor conduits, and it will be much more under your control as to which path (or paths) your current will travel.

Hi,
Something to note about RGB LEDs
The perceived brightness( what you think it looks like) and actual brightness(the actual duty cycle) is NOT the same.
Use this equation to figure it out :
Perceived brightness percent = 50 log (Actual Brightness percent)

Also, the intensity ratio for the RGB is the following R:G:B=3:6:1

Last night I tried out Halley/Grumpy Mike's system. After spending an hour debugging my code (I'm rusty), it works fine. Thanks a lot, everyone.

Airman: I suspected that it wasn't quite that simple. Some of the hex codes I sent looked very much like the actual and some not so much. Also, I was not in a dark room, so I know that that would mess with colors.

Is the log thing a function of the human eye picking up color on a log scale (like the ear) or the LED emitting light nonlinearly?

Also, is the ratio you listed taking into account the 100[ch937] resistor other people suggested for the blue or not? And what effect would a resistor have on brightness in general? The closest I had to a 220[ch937] was like 190[ch937]. If you have answers to these questions, that'd be awesome. Thanks.

Is the log thing a function of the human eye picking up color on a log scale (like the ear) or the LED emitting light nonlinearly?

Both. Not sure where airman got the equation. For TVs and other mostly-linear displays, this is where the "gamma correction" comes in. LEDs are almost like snowflakes, no two alike.

Also, is the ratio you listed taking into account the 100[ch937] resistor other people suggested for the blue or not?

The individual resistors are calculated on the individual ratings for each LED inside the multi-LED package. Your package has a datasheet available that will tell you the sustained current limit and the forward voltage. Blue LEDs typically have different needs from reds and greens. You'll need to learn the "how to calculate a resistor for an LED" equation. Being off by 10%~15% (190ohm vs 220ohm) is not that big a deal; the actual calculation may say you need a 203ohm anyway. Better to go higher than lower though.

So it sounds like I need to look at the datasheet? Looks like this little experiment is coming to an end. I got it from RadioShack so I don't think I'll be finding a datasheet. The package came with a few specs, like wavelengths, but I threw that away long ago. How many times do I have to learn not to buy stuff from RadioShack? Unless I need it right away, I can get it cheaper online with a better selection and a datasheet to boot!

I wouldn't bother trying to implement a LOG function in an embedded system it is just not worth the processing cycles most of the time when dealing with LEDs. Unless that is you want an exact measure of brightness for some special purpous. Just experiment with a few values of resistor from 150R upwards.

You will find that if you put some sort of diffuser over the LED it mixes the colours up very well. Look at the video at the end of this link to see what it can look like.
http://www.thebox.myzen.co.uk/Hardware/Mini_Monome.html

I have to agree with the the replies but would someone tell me how you guys knew exactly what wasp is doing? Did I miss part of the conversation, or is it a well- known project?