Calibrate an RGB led to display ANY color.

Hi all, I am testing a RGB led (the included in starter kit) and I am providing each input different voltages via PWM pins.

When I give them mono color values like (255, 0, 0), (0, 255, 0) and (0, 0, 255) The led works perfectly, but if, for example, provide him white (255, 255, 255), the led is not white, it shows a "purpled white".
I googled a few and found that the reason is that each "inner LED" has it's own voltage specs.

True, the datasheet says:

Now I edited my code. Blue and green pin works with same voltage, but red brights more with less voltage. To calibrate the red I change my analogWrite to red. Let's assume that 3.3V is 255.
1.95 Volts should be 255 in red led: redValue * (1.95 / 3.3) is the new code to write to redPin.

Now white looks more white, but if I try to show other color, like brown(103, 64, 58), the result is ridiculous:


Pink :slightly_frowning_face:

How can I represent real colors with this led?

The code:

const int redPin = 11;
const int greenPin = 9;
const int bluePin = 10;

int redValue = 0;
int greenValue = 0;
int blueValue = 0;

void setup() {
  Serial.begin(9600);
  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(bluePin, OUTPUT);
  
  redValue = 103;
  greenValue = 64;
  blueValue = 58;
}

void loop() {
  updateLed();
}

void updateLed(){
  analogWrite(redPin, redValue * 1.95/3.3);
  analogWrite(greenPin, greenValue/3.3);
  analogWrite(bluePin, blueValue/3.3);
}

Now I edited my code. Blue and green pin works with same voltage, but red brights more with less voltage. To calibrate the red I change my analogWrite to red. Let's assume that 3.3V is 255.
1.95 Volts should be 255 in red led: redValue * (1.95 / 3.3) is the new code to write to redPin.

No point. The voltage / current for any LED is not related very much to the actual brightness. The colour output also depends on the LED, see the data sheet for the colour output curves, but don't expect to be able to do much with them.

but if I try to show other color, like brown(103, 64, 58), the result is ridiculous:

Yes brown is almost impossible. I have never been able to get an acceptable brown on an LED.

How can I represent real colors with this led?

You can't, with that or any single LED.

One problem is that the way we perceive colours depends on the colours that surround it and the context in which we see them.

In the attached image the squares A and B are exactly the same colour.

Put it into a graphics package an use the eye dropper to see the RGB values of the two squares.

This means that rgb leds are pointless if I don't use hundreds of them :slightly_frowning_face:

Thanks for solving my doubts. Interesting image.

This means that rgb leds are pointless

Depends what you mean by pointless. I agree that you can't display any colour unless you have control of the background illumination but you could do that with two LEDs.