LED Trouble with Internet Connected Lamp - Getting Started With Arduino

Hi all,

I'm new to Arduino and electronics. I am working through the book "Getting Started With Arduino" and am having trouble switching from regular LED's to an RGB LED. I bought the LED from Radioshack and hooked it up yesterday. I followed the instructions in the book and was not able to get it to work. After an hour of trying to figure out what I did wrong I hooked it up opposite of what the book instructed and it worked... Problem is, now I don't know how to control each individual color...

The LED is currently hooked up like so, and works: pin 13 is hooked up to the long lead on the LED (the lead which I thought was supposed to go to ground) each short pin has a 10k resistor between it and a wire leading to ground...

I previously hooked it up like so, which didn't work: pins 11, 12, 13 eached hooked to a short lead on the LED with a 10k resistor between the pin and the LED the longer lead from the LED is hooked to ground...

With the current working set up I only have one pin to control so it lights all colors on the LED. Can someone please offer some advice? I'm using a Mega 2560 board. (on a side note, I was looking to control the LED using the analogWrite() function... which pins are capable of that?)

Thanks in advance,

Ryan Worcester

Sounds like the polarity of the LED is opposite to what you expected, presumably you've bought a common anode LED whereas the circuit is designed for a common cathode one.

Given the behaviour you describe, I'd suggest you connect the common (long) lead to 5V and connect each short lead via a resistor to an Arduino pin. Then take the pin LOW to light the LED.

You might want to double check the resistor rating - 10KOhm sounds rather high to me, but you do need to ensure you stay within the current rating of the LED and also keep the current at each Arduino pin below about 20 mA.

That did the trick, sort of... If I use one pin I get one of the expected color; red, green, or blue... If I use them all at the same time at different brightnesses to mix colors for the lamp it always shows a light blue color. I tried fading through all pins individually, I found an example sketch with code that does so, and it gave shades of violet, green, and light blue... I can't achieve pure colors this way, any advice here?