How to get LED displaying exact RGB colors?

Hello,

I'm passing three values (R,G,B) to Arduino from a Python file (via pyserial) and lighting up the LED included in the starter kit (which I believe is 'common cathode') as discussed in project 4 "Color Mixing Lamp".

Everything is 'working' and the LED shows expected results for values like:

255, 0, 0 - Shows Red
0, 255, 0 - Shows Green
0, 0, 255 - Shows Blue

Some mixed colors however, don't appear as they would, for example, in a color chooser application.

For example the LED output for "19, 235, 26" appears light purple, whereas it should actually appear lime green.

See Online RGB Color Wheel for an example.

Is this a 'known' scenario?

Perhaps if I used more expensive LED's or a RGB led strip, the colors would be more accurate?

Thank You.

Arduino Code

// digital output pin numbers
const int digitalOutputPinForRedLED = 9;
const int digitalOutputPinForGreenLED = 10;
const int digitalOutputPinForBlueLED = 11;

// global variables
int valueOfRed = 0;
int valueOfGreen = 0;
int valueOfBlue = 0;
int x = 1;

void setup() {
  // initialize serial communications at 9600 bps:
  Serial.begin(9600); 

  // set digital pin modes
  pinMode(digitalOutputPinForRedLED,OUTPUT);
  pinMode(digitalOutputPinForGreenLED,OUTPUT);
  pinMode(digitalOutputPinForBlueLED,OUTPUT);
}

void loop() {
    
  if (Serial.available()) {
    if (x==1) {
     valueOfRed = Serial.read();
     Serial.print("Red: ");
     Serial.println(valueOfRed);
     analogWrite(digitalOutputPinForRedLED, valueOfRed);
   }
    else if (x==2) {
     valueOfGreen = Serial.read();
     Serial.print("Green: ");
     Serial.println(valueOfGreen);
     analogWrite(digitalOutputPinForGreenLED, valueOfGreen);
   }
    else if (x==3) {
     valueOfBlue = Serial.read();
     Serial.print("Blue: ");
     Serial.println(valueOfBlue);
     analogWrite(digitalOutputPinForBlueLED, valueOfBlue);
   }
   x++;
 }
    else {
      x = 1; 
     }
delay(1);
}

Python Code

import serial
import struct
ser = serial.Serial('/dev/ttyACM0', 9600)
red_value = int(request.GET.redvalue)
green_value = int(request.GET.greenvalue)
blue_value = int(request.GET.bluevalue)
ser.write(struct.pack('>3B', red_value, green_value, blue_value))

Many RGB LEDs need different resistor values on each color. It looks like you have the same value on all 3. Also open the Serial Port Monitor, to be sure what you're actually receiving on the port.

Thanks for the reply.

Re: Different resistors:

I am using the common cathode RGB led from the starter kit. How would I be able to tell which resistors were required for each color?

Re: Serial Print Monitor values:

They are written with Serial.println() in the loop (see code in OP), and they are correct.

Thanks again.

It seems that the intensity of the green in this LED is not very intense compared to the blue and red. You'll need to search on others experiences with this LED.

http://forum.arduino.cc/index.php?topic=22413.0

http://forum.arduino.cc/index.php?topic=206731.0