[Solved]Incorrect colours from RGB LED

Need help to get correct colours from RGB common anode LEDs.
It's weird that the red colour code is 255,0,0 but I need to pass 255,255,0 to my Arduino mini pro to get red colour.
Also, 0.255.255 to get green and 255,0,255 to get blue. Most samples I found only the web, they only need single 255 to get R,G,B colours correctly.

Please help!

I have verified all the pins and they should be all correct.
RGB LED pins are connected to Arduino mini pro:
R=pin 6
Comm andode =pin VCC
G=pin 5
B=pin 3

I need the code below to get me red colour:

  analogWrite(PIN_RED,  255);
  analogWrite(PIN_GREEN,  255);
  analogWrite(PIN_BLUE,  0);

Mac OS 10.9.4
Arduino mini pro 16Mzh

Stonez56

(deleted)

Where is your common connected? Is it a common Anode(+ve) or common Cathode(-ve) RGB LED, If its in GND at the moment,, change it to +5v and vice versa

Thanks for the quick reply!

LED Common is now connected to VCC. I tried to connect the common to GND, then it won't work at all.

Using common anode LED, 255 is off and 0 is full on.
If pins are connected correctly:

  analogWrite(PIN_RED,  0);
  analogWrite(PIN_GREEN,  255);
  analogWrite(PIN_BLUE,  255);

Will turn red fully on.

stonez56:
I have verified all the pins and they should be all correct.
RGB LED pins are connected to Arduino mini pro:
R=pin 6
Comm andode =pin VCC
G=pin 5
B=pin 3

I need the code below to get me red colour:

  analogWrite(PIN_RED,  255);

analogWrite(PIN_GREEN,  255);
 analogWrite(PIN_BLUE,  0);

That means you have your led connections reversed! It's happened before. :slight_smile:

You've got PIN_GREEN connected to Anode and PIN_BLUE connected to red cathode, which is why that particular code lights up the red led.

Using common anode LED, 255 is off and 0 is full on.
If pins are connected correctly:

  analogWrite(PIN_RED,  0);

analogWrite(PIN_GREEN,  255);
  analogWrite(PIN_BLUE,  255);



Will turn red fully on.

Hi elac,
Thank you so much! This is exactly what happen to my RGB LED!
I tested and it worked!

However, the colour code input might have R 86, G 201, B 100. How should I handle this conversion?
Do you have a sample I can take a look? Thanks!

Stonez56

Subtract the values from 255 and use the difference.
Example: R=86: 255-86=169, G=201: 255-201=54, B=100: 255-100=155

analogWrite(PIN_RED, 169);
analogWrite(PIN_GREEN, 54);
analogWrite(PIN_BLUE, 155);

Hi elac,

Subtract the values from 255 and use the difference.
Example: R=86: 255-86=169, G=201: 255-201=54, B=100: 255-100=155

It worked! I take 255 to minus the original R,G,B code and the colour showing correctly now.
Thanks!!

Glad you got it straightened out.