Go Down

Topic: How to get LED displaying exact RGB colors? (Read 3376 times) previous topic - next topic


Jan 10, 2015, 01:56 pm Last Edit: Jan 11, 2015, 01:03 pm by oshihirii Reason: Added image.

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 http://www.colorspire.com/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

Code: [Select]
// 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:

  // set digital pin modes

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

Python Code

Code: [Select]
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.



Go Up