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
}