3

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?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
A.W.
  • 2,858
  • 10
  • 57
  • 90

3 Answers3

6

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.

Jamie F
  • 23,189
  • 5
  • 61
  • 77
  • Ok I wil try that. Tested a loop with random(256) for all three pins and see lots of blueish and reddish colors. I will adjust the resistors. – A.W. Dec 02 '11 at 20:31
2

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?

Valera Kolupaev
  • 2,285
  • 14
  • 14
  • Yes it's weird. Just new to Arduino, don't know how to configure it. I will try adjusting resistors – A.W. Dec 02 '11 at 21:17
  • 2
    You may want to play with this http://arduino.cc/en/Tutorial/SecretsOfArduinoPWM to get idea about PWM configuration. – Valera Kolupaev Dec 02 '11 at 21:23
2

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.

on8tom
  • 1,766
  • 11
  • 24