RGB LED Producing Incorrect Colors

I'm trying to use a single RGB LED but am having issues with the color output.

Materials:

  • Common anode RGB LED
  • 100 ohm resistor (for red)
  • 150 ohm resistor x2 (for green and blue)

Wiring:

  • 5V --> +
  • Pin 3 --> R
  • Pin 5 --> G
  • Pin 6 --> B

I've labelled the color each line produces when the others are commented out. Below that I have shown the colors produced when combining the specified pins and commenting the other line out.

Code:

#define RED_PIN 3
#define GREEN_PIN 5
#define BLUE_PIN 6

void setup() {
  pinMode(RED_PIN, OUTPUT);
  pinMode(GREEN_PIN, OUTPUT);
  pinMode(BLUE_PIN, OUTPUT);
}

void loop() {

  // 1
  analogWrite(RED_PIN, 255); // BLUE-GREEN
  // 2
  analogWrite(GREEN_PIN, 255); // PURPLE-BLUE
  // 3
//  analogWrite(BLUE_PIN, 255); // YELLOW-GREEN

  // 2 and 3 make red
  // 1 and 3 make green
  // 1 and 2 make blue
  // 1, 2, and 3: LED doesn't turn on
}

Common cathode needs to go to Gnd, then High's from the pins will light up the colors.

CrossRoads:
Common cathode needs to go to Gnd, then High's from the pins will light up the colors.

The LED is actually common anode I apologize, I updated the post.

Michael, this behavoir is as expected with your code and a common anode led. Because the Arduino pins are "sinking" current from 5V through the LEDs, analogWrite(RED_PIN, 0) will make red full brightness and analogWrite(RED_PIN, 255) will switch red off. Do you have a question?

It worked thank you so much!

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.