RGB LED Common Anode

Status
Not open for further replies.
So I'm using a common anode RGB LED. I didn't intend on using anode but I ordered the wrong ones. Whatever.... So I've got it wired up correctly and I'm able to get the correct colors I want. I'm just trying to blink on and off through a series of different colors. The problem is when the LED is supposed to be completely off. It's very dim white but not completely off. Has anyone run across this before?

I tried different RGB LED's including a common cathode LED I had. (I altered the wiring for cathode LED of course.)

Also, I tried it with an Arduino Uno and it worked perfectly. Is this possibly a difference between Ardunio and Teensy?

Here's the code:

int redPin = 5; // Red LED, connected to digital pin 3
int greenPin = 4; // Green LED, connected to digital pin 4
int bluePin = 3; // Blue LED, connected to digital pin 5

void setup() {
// put your setup code here, to run once:

}

void loop() {
// put your main code here, to run repeatedly:
rgbOrange();
delay(1000);
rgbOff();
delay(1000);

rgbPurple();
delay(1000);
rgbOff();
delay(1000);

rgbYellow();
delay(1000);
rgbOff();
delay(1000);
}

void rgbOff()
{
analogWrite(redPin, 255); // Write current values to LED pins
analogWrite(greenPin, 255);
analogWrite(bluePin, 255);
}

// These color values are based on Common Anode RGB LED's, not Cathode so LOW = 1, HIGH = 0
void rgbOrange()
{
analogWrite(redPin, 0); // Write current values to LED pins
analogWrite(greenPin, 175);
analogWrite(bluePin, 255);
}

void rgbPurple()
{
analogWrite(redPin, 0); // Write current values to LED pins
analogWrite(greenPin, 255);
analogWrite(bluePin, 0);
}

void rgbYellow()
{
analogWrite(redPin, 0); // Write current values to LED pins
analogWrite(greenPin, 75);
analogWrite(bluePin, 255);
}
RGB LED.png
 
analogWrite(pin, 255) will cause a PWM signal that's high 255 out of 256 timer clocks. So you'll still get a tiny amount of light this way.

To completely turn the LED off, use analogWrite(pin, 256), or pinMode(pin, OUTPUT) and digitalWrite(pin, HIGH).
 
Thanks for the quick reply.

I should have mentioned that I started out using pinMode("pin", OUTPUT) and setting the pins to HIGH. When I do that or set the pins to 256, the LED stays a dim red. It's strange because the Arduino Uno doesn't do that.
 
Ok, so I just noticed that I was using 5V instead of 3.3V. It's working now. I'm assuming that using 5V will eventually damage the LED. It's so much brighter at 5V. :) Thanks!
 
I read through the article and I think I understand. I think I have plenty of resistance according to the math. I may be doing it wrong though.

I'm using 6V to power the Teensy.

And just a reminder, these LED's are common anode.
Red: 6V - 2.5V = 3.5V (left over) ==> 3.5V/.020A = 175 Ohms
Green and Blue: 6V - 4.5V = 1.5V ==> 1.5V/.020A = 75 Ohms

I'm using 220 Ohms resistors. Shouldn't that be more than enough to take care of the extra voltage? Or am I doing this wrong? I must be because when I power it from the USB the LED's are very dim when off and when I'm powering it from 4 AA's it's much brighter when off.

Thanks again.
 
Status
Not open for further replies.
Back
Top