Common anode RGB LED

Well it is the code I copied and pasted directly from my arduino software. It works great when I use common ground on separate LEDs but I just bought a common anode LED and it doesn't work now. The pins are right there in the code..3, 5, 6. I'm a bit confused by your response. The code I posted is what I am uploading to the arduino board. But it has to be changed so that in will work with a common anode LED. So I need to set the pins 3, 5, 6 to output as negative and not positive. What do I need to change in the code above for that to happen?

Wire the anode to +5V and the cathodes through your resistor to the input pin. Then the code will be logically inverted. That is a low will turn the LED on and a high off.
This is the normal way to drive LEDs and it is called current sinking.

So instead of the code saying Output I should change it to input? I have already wired it all up but the RGB LED just lights up all three colors. What do I change in the code for it to work? Thanks for your help.

No they should not be inputs.
A digital write to a pin will set the output. Set it low to turn the led on and high for it to be off.
If you have already wired them up then you will have to rewire them.

Yea I just rewired them the way you said with positive to common anode and the rgb pins to the arduino. However there is no High or Low in the code I posted. It is Analog write and constrain. This is for an app on my android phone which works awesome with a common cathode. But like I said I am now using a common anode LED and it doesn't work because I do not know what to change in the code. I understand the High and Low thing but this code doesn't have that in it.

I understand the High and Low thing but this code doesn't have that in it.

For the code it is not High and Low: it is HIGH and LOW

Yes it is HIGH and LOW. However like I said the code I am using doesn't use that. All I need is the pins 3, 5, 6 to be ground and not positive. What do I need to change in the code I posted to achieve this? Thanks.

PMW should work wit common cathode and common anode as well

You should change pinMode() as an INPUT when you are using common anode(+)
if you are using common cathode(-) use pinMode() as an OUTPUT...

the the common pin goes to 5v if is an anode or to GND if it is cathode

the color pins goes to they'er respective pin in the IC, already configured in software as an INPUT or OUTPUT.

Yes it is HIGH and LOW. However like I said the code I am using doesn't use that. All I need is the pins 3, 5, 6 to be ground and not positive. What do I need to change in the code I posted to achieve this? Thanks.

I don''t understand that. ?

First thing, I can't read your code. Try reformat it.
For pin 3 to be ground,

  pinMode ( 3, OUTPUT );
  digitalWrite ( 3, LOW);
const int redPin = 3;

const int greenPin = 5;

const int bluePin = 6;




const int redPin2 = 9;

const int greenPin2 = 10;

const int bluePin2 = 11;




#define REDPIN 3

#define GREENPIN 5

#define BLUEPIN 6




#define FADESPEED 5 




void setup() {


Serial.begin(9600);



pinMode(redPin, OUTPUT); 

pinMode(greenPin, OUTPUT); 

pinMode(bluePin, OUTPUT); 




pinMode(redPin2, OUTPUT); 

pinMode(greenPin2, OUTPUT); 

pinMode(bluePin2, OUTPUT); 




Serial.print("Arduino control RGB LEDs Connected OK ( Sent From Arduinno Board )");

Serial.print('\n');

}




void loop() {



while (Serial.available() > 0) {

 

 int red = Serial.parseInt(); 


 int green = Serial.parseInt(); 


 int blue = Serial.parseInt(); 


 int red2 = Serial.parseInt(); 


 int green2 = Serial.parseInt(); 

 // do it again:

 int blue2 = Serial.parseInt(); 


 if (Serial.read() == '\n') {

  
 red = constrain(red, 0, 255);

 green = constrain(green, 0, 255);

 blue = constrain(blue, 0, 255);

   

 red2 = constrain(red2, 0, 255);

 green2 = constrain(green2, 0, 255);

 blue2 = constrain(blue2, 0, 255);


 analogWrite(redPin, red);

 analogWrite(greenPin, green);

 analogWrite(bluePin, blue);

   

 analogWrite(redPin2, red2);

 analogWrite(greenPin2, green2);

 analogWrite(bluePin2, blue2);


Serial.print("Data Response : ");

 Serial.print(red, HEX);

 Serial.print(green, HEX);

 Serial.println(blue, HEX);

 }

}




}

No where in that code is digitalWrite, HIGH, LOW, etc.... They are analog write on pins 3, 5, and 6. As the code sits, pins 3,5, and 6 all have positive voltage coming from them. I need the code to be changed so that they are ground as I am using a common anode LED. Thanks.

I changed the code to say INPUT instead of OUTPUT and uploaded code to arduino. But now when I open the app to control the RGB LED all 3 colors are always on and when I move the sliders to change the color the LED gets dimmer as I move up. It's like backwards. But they never shut off. I am really close I think I just need some more help. Any other thoughts please??

Yes, with your common anode device, full-on will be with analogWrite(pin,0) and full-off will be with analogWrite(pin,255)

Change

analogWrite(redPin, red);
analogWrite(greenPin, green);
analogWrite(bluePin, blue);

to

analogWrite(redPin, (255-red));
analogWrite(greenPin, (255-green));
analogWrite(bluePin, (255-blue));

I hope we have a resistor between each LED cathode and its corresponding Arduino output/pwm pin.

Thank you Pancake!! You just made my night. Possibly my week! Works awesome. Thank you again!!! XD

Way cool.

Could you possibly offer me insight on this: Attiny84 and Arduino - Project Guidance - Arduino Forum

I am trying to put this project on an attiny84. Everytime I try to verify I get an error. Please have a look. Thanks again.

Okay scratch that. What would I change this to?

analogWrite(redPin, map(colors[0], 0, 255, 0, max_red));
  analogWrite(greenPin, map(colors[1], 0, 255, 0, max_green));
  analogWrite(bluePin, map(colors[2], 0, 255, 0, max_blue));

Same issue here with the code being written for common cathode. As you are aware I am using a common anode. I already changed the OUTPUT to INPUT and it works it's just the colors don't match on the LED when I select the corresponding color from my android app. Thanks again.

I already changed the OUTPUT to INPUT and it works

Then change them back, the pins must be an output.
Using PWM. The values are reversed, so if you have a value val then you need to subtract it from 255.

analogWrite(pin,val); // for common cathode
analogWrite(pin,255 - val); // for common anode

So in your code you an change the map values or simply do

analogWrite(bluePin, 255 - map(colors[2], 0, 255, 0, max_blue));

ehrja:
You should change pinMode() as an INPUT when you are using common anode(+)
if you are using common cathode(-) use pinMode() as an OUTPUT...

the color pins goes to they'er respective pin in the IC, already configured in software as an INPUT or OUTPUT.

This is rubbish, please do not post rubbish.

What happens when you do this is that instead of setting spin high or low you switch the pull up resistor on or off. This resistor is about 30K so if you just use a scope it will look to have inverted things but the current you get out of it is very limited. So under a restricted set of conditions you get the illusion it is working.

Mike when I leave the code as OUTPUT the RGB LED stays on at all colors. Even when changing the code as you suggested. I change them to INPUT and all works fine. So I am confused as to why you say leave as OUTPUT?

I say use it as outputs because that is what you must do to output to a device.
If you have the pins as inputs all the current supplied goes through the internal pull up and the current output is very limited.
If you say it does not work when the pins are outputs you have something else wrong. To find out what it is we need to see a schematic of how you have wired it up along with all the code you are using.
What resistor values are you using?