Question

I have an RGB LED and have pins to 9, 10, 11 and a pin to ground. Resistors have been provided for R, G, and B.

When I do:

  analogWrite(r, 255); // I see a red color
  analogWrite(g, 0);
  analogWrite(b, 0);

  analogWrite(r, 0);
  analogWrite(g, 255); // I see a green color
  analogWrite(b, 0);

  analogWrite(r, 0);
  analogWrite(g, 0); // I see a blue color
  analogWrite(b, 255);

When I do:

  analogWrite(r, 153);
  analogWrite(g, 102);
  analogWrite(b, 51);

it does not look brown to me, more like a blue color. Am I missing something I need to do?

Was it helpful?

Solution

Brown is a very difficult color to achieve. (It's actually dark red. Brown isn't in the rainbow.)

Make sure that your colors are balanced: write a dim white / gray, 128, 128, 128 and make sure this looks white. Then write a 255, 255,255 and make sure this looks white. If these don't look white, adjust your resistors to reduce current through the component that is too bright (be careful not to allow too much current and burn out the LED.

OTHER TIPS

Brown color example

Its weird, but blue color seems exactly opposite to brown color, that you are trying to achieve. Moreover, when I've tried to invert the color (255 - x), I've got blue colors. Maybe something is wrong with PWM configuration?

is the RGB LED common anode or common cathode,

usually RGB LEDs are common anode.
this means: lowwer the analogWrite value, higher brightness (more emitted light)

http://www.hertaville.com/wp-content/uploads/2011/07/rgb.jpg

you also need resistors, notice that blue emits more light with the same value of resistans, than green or red, so you need to set a higher resistor value.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top