Green LED overpowered by blue and red

So, I was putzing around with the color mixing tutorial here: http://www.ladyada.net/learn/arduino/lesson3.html (the last bit, where you make the little paper box).

I ordered three super-bright LEDs, and everything works as expected but for one small hitch: the red and blue LEDs overpower the green. When all three are at full power, the light is decidedly purple, and the green quickly disappears when the others are turned on (stays lit, just gets washed out by the other two).

I was concerned about this when I purchased the LEDs, so I tried to match the luminosity as closely as I could; I ended up with 2,200 mcd LEDs for the green and blue and 2,000 mcd for the red. Clearly, there's something else I should've been looking at to balance them out.

So my questions are:

A) What other factors should I look at when evaluating whether LEDs will mix properly?

B) Given the datasheets for these three (see below), is there any way I can balance them by using different resistance values or something? I started out with each of them running off a parallel pair of 470-ohm resistors, giving about 235 ohms total (because I didn't have anything between between 470 and 150) and around 20 mA current. I tried switching the green to a 150-ohm resistor to push its current up around 30 mA, but this doesn't appear to have made any difference.

For what it's worth, the code I was testing with is:

#define RED 9
#define GREEN 10
#define BLUE 11

void setPixel( byte r, byte g, byte b )
{
    analogWrite( RED, r );
    analogWrite( GREEN, g );
    analogWrite( BLUE, b );
}

void setup()
{
    pinMode( RED, OUTPUT );
    pinMode( GREEN, OUTPUT );
    pinMode( BLUE, OUTPUT );
    digitalWrite( RED, LOW );
    digitalWrite( GREEN, LOW );
    digitalWrite( BLUE, LOW );
}

void loop()
{
    setPixel( 127, 127, 127 );
}

DATASHEETS Red: http://www.alliedelec.com/Images/Products/Datasheets/BM/AND/505-5260.PDF Green (5mm): http://www.alliedelec.com/Images/Products/Datasheets/BM/SLOAN_COMPANY/265-9051.PDF Blue: http://www.alliedelec.com/Images/Products/Datasheets/BM/KINGBRIGHT/436-0236.PDF

If I understand correctly, you are using the same 470/2 resistors for each color? They have to be different, check on a link how to calculate right nominal: http://www.whatcircuits.com/led-calculator/

Hey, thanks for the link. Very helpful.

According to that, I need 100-ohm resistors for the red and green, and 56 ohms for the blue. So apparently I've been calculating resistor values incorrectly.

Just to make sure I'm understanding this part of it: I've been calculating the resistor values based on the supply voltage (5V from the Arduino pin), but that's not actually correct, is it? I should've been using the forward voltage of the LED.

Wait. That doesn't seem to work out either. The blue LED has a forward voltage of 3.3V and a forward current of 30 mA, which would give me (3.3 / .03 = 110 ohm). But the calculator says 56 ohms. What am I missing?

As a side note, I clearly need to order some smaller resistors. What do people think of this pack: http://www.sparkfun.com/products/10969 (setting aside questions of the silliness of having a 0-ohm resistor)

Ohm's law: I = V / R. , where V is voltage across R, Vr = V(power) - V(led);

Resistor = (5V-Vforward)/20mA (5V-3.3V)/.02 = 85 ohm

30mA is usually max current forward at 1/10 duty cycle - you'll burn it out running it that high continuously. Lower the other 2 instead.

Ahhh, gotcha.

So, with LEDs at 1.9Vf, 2.0Vf, and 3.3VF and running each of them at 20 mA, I get:

3.1V / .02 = 155 ohm (red) 3.0V / .02 = 150 ohm (green) 1.7V / .02 = 85 ohm (blue)

Basically, the resistor deals with whatever voltage the LED doesn't? Makes sense.

Exactly, the current is determined by the voltage drop across the resistor.

Also, the eye can be more sensitive to some colors than others, so you may need to tweak currents to provide perceived level matching.

Hmm. If I crank green all the way up to full (255), I can get a whitish light with red and blue at around 15-20. Anything higher than that and it gets noticeably purple again. My eye can’t be that far off, can it? (I mean, my vision’s pretty crap, but really…)

I’m attaching the red and green through 150-ohm resistors, and the blue through a 100 and a 470 in parallel. The schematic’s attached.

Only you can say. I am somewhat red/green colorblind (seems to be a common guy thing) so what looks good to me may look off to others.
Try doubling the resistance for the overpowering colors, see if that will allow more range of PWM adjustment to get a mix you like.

Could also be the angle at which you are viewing the LEDs.

I played with the resistors a bit last night, but didn't notice any significant changes. However, I then decided to just run with it as-is and was able to produce at least the six basic colors plus white. Given that this was strictly a learning project for me without any kind of purpose in mind, that's probably good enough.

Thanks for the help, guys.