Can't Figure out RGB LEDs... embarassing, heh...

Hey guys,

So, this is week one with the Arduino for me. I ran through a number of simple tutorials online, then I went through the Getting Started with Arduino book. I had no problems whatsoever, but when I got to the end of the book, it makes the suggestion to change the final project… a three LED lamp… from three LEDs to a single RGB LED.

It just so happened that I had a few, so I set about trying this out. Somehow or another, I’m just not understanding things.

Here’s how I have it setup

1 3 and 4 on the RGB LED are wired from 330 Ohm resistors to digital pins 9, 10 and 11. 2, the longest, is wired to ground.

My sketch looks like this:

int RED = 9;
int GREEN = 0;
int BLUE = 11;

void setup()
{
pinMode(RED, OUTPUT);
pinMode(GREEN, OUTPUT);
pinMode(BLUE, OUTPUT);
}

void loop()
{
for(int r = 0; r < 1024; r+=5) {
for(int g = 0; g < 1024; g+=5) {
for(int b = 0; b < 1024; b+=5) {
analogWrite(RED, r);
analogWrite(GREEN, g);
analogWrite(BLUE, b);
delay(30);
}
}
}
}

I have no idea why this wouldn’t work. I can’t figure out how to dumb it down from here either. I know the LEDs work because, if they’re wired to ground and I touch one of the color poles, it faintly lights up.

Sorry for the stupid question. I just refuse to accept defeat from something as simple as this.

Doh, yes it should be. I had switched them around earlier and missed that.

You just figured it out for me. I didn't realize it could be common anode or common cathode. Applying 5v to the pin I assumed was a common ground and grounding the others instantly brought it to life.

Phew. Thought I had been beaten, haha.

Thanks a ton for your help.

you properly tested the rong way

common anode or common cathode (common + or common -)

have a look in the led is it clear can you see the a pin that is other then they others… (mostly one of the 2 middle pins) then the single one beside it is red the other to are green and blue :stuck_out_tongue:

hope you can figure it out now :stuck_out_tongue:

note:
I always plug it directly to the board on pins 3,4,5 and 6
4 being HIGH or LOW depending what kind of led it is :smiley:
3,5 and 6 are pwm
Don’t them on to long! use 220R resistors for that this is just for testing.

Here’s something interesting to try with your RGB LED. Basically it flashes the LED a specified color that you make with 3 potentiometers.:

int ledRGB = {9, 10, 11};

int potenVal1 = 0;
int potenVal2 = 0;
int potenVal3 = 0;

byte myColor = {potenVal1, potenVal2, potenVal3};

void setup(){
for(int i = 0; i < 3; i++){
pinMode(ledRGB*, OUTPUT); //Set the three LED pins as outputs*

  • } *
  • setColor(ledRGB, BLACK); //Turn off led*
    }
    void loop(){
  • changeLuminosity();*
  • flashOneColor(ledRGB, myColor);*
    }
    void setColor(int* led, byte* color){
  • for(int i = 0; i < 3; i++){ *
    analogWrite(led_, color*);
    }
    }
    /changes luminosity and color of an RGB LED/
    void changeLuminosity(){
    //analog input pins to read potentiometer voltages from*
    * int potenIn1 = 7;
    int potenIn2 = 6;
    int potenIn3 = 5;*_

* //read the voltage on the potentiometer pins and scale these to a range of 0-255 (common anode)*
* potenVal1 = 255 - (analogRead(potenIn1)/4);*
* potenVal2 = 255 - (analogRead(potenIn2)/4);*
* potenVal3 = 255 - (analogRead(potenIn3)/4);*

* //write color values to LED pins*
* analogWrite(ledRGB[0], potenVal1);*
* analogWrite(ledRGB[1], potenVal2);*
* analogWrite(ledRGB[2], potenVal3);*

* //save color created by user in color array myColor[]*
* myColor[0] = potenVal1;*
* myColor[1] = potenVal2;*
* myColor[2] = potenVal3;*
}