Common Anode RGB LED Question

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Common Anode RGB LED Question

Postby KeyboardKowboy » Sun Nov 21, 2010 7:10 pm

Hi everyone, I'm new to the forums and have just recently begun playing around with the Arduino. I'm a software engineer by trade, but have always been interested in electrical engineering, and so have been learning from the best... all you Adafruiters!

Here's my situation... I was at radio shack the other day and decided to pick up an RGB LED. The package reads "5mm High Brightness Full-Color LED". Now in my ignorance at the time, I didn't realize there were both common cathode and common anode rgb led's. I began breadboarding the LED and quickly realized I had grabbed a common anode led. Is there a way I could have determined this on the package?

Determined to get the LED to do my bidding, I soon realized that if I connect the cathodes to digital pins on the arduino and set the pins to HIGH, I got the full mix of R, G, and B values. So I began setting two pins to LOW, and I was able to then selectively pick the color I wanted.

If the arduino digital pin is set to output (which they are in my situation), how is it that setting them LOW makes that pin act as a ground? :?:
Memory is necessary for all the operations of reason. --Blaise Pascal
KeyboardKowboy
 
Posts: 39
Joined: Sun Nov 21, 2010 6:46 pm
Location: Rochester, NY, USA

Re: Common Anode RGB LED Question

Postby adafruit_support_bill » Sun Nov 21, 2010 8:41 pm

Setting a digital output pin LOW will set it to ground potential. HIGH will set it to +5v.
User avatar
adafruit_support_bill
 
Posts: 16627
Joined: Sat Feb 07, 2009 9:11 am

Re: Common Anode RGB LED Question

Postby Alan Chatham » Sun Nov 21, 2010 10:44 pm

Exactly - the "OUTPUT" designation refers to the idea that you're going to be driving a line high or low with the pin, so you can either output some current at +5V, or sink some current into the pin at 0V.
The "INPUT" designation more implies that you'll be reading whether or not the line connected to it is high or low, but not really impacting the current/voltage on the pin.

The one minor (but super-convenient) caveat to this is that the chip in the Arduino does have controllable internal pull-up resistors on each pin, so you can do the following
Code: Select all
pinMode(PIN, INPUT);
digitalWrite(PIN, HIGH);

and it will turn this pull-up resistor on, so your input pin will be pulled HIGH with a 20-50K ohm resistor. This means that if the pin isn't connected to anything, the voltage on it will be pulled up to +5V, but the pin is still easy to pull down to ground (by a switch or something).
OpenChord.org - Open Source kits to let you play Guitar Hero with a real guitar, or build your own Wii/banned/USB controllers.
Alan Chatham
 
Posts: 143
Joined: Thu Feb 04, 2010 1:30 am

Re: Common Anode RGB LED Question

Postby KeyboardKowboy » Mon Nov 22, 2010 12:40 am

Fantastic. Thanks for the replies. I was hoping that's what was going on.

As for my other question... how would I be able to determine (from the package) that I was buying a common ANODE led and not a common CATHODE led. Anything specific I should look for in the future? Granted I know it doesn't matter much, but I think the code is easier to read and maintain when setting a pin HIGH to turn something on, as opposed to setting the pin LOW to turn certain colors on like in my situation. Thanks again for the help.

(Oh, and I was able to use PWM (analogWrite) to fade in and mix colors... sweet...)
Memory is necessary for all the operations of reason. --Blaise Pascal
KeyboardKowboy
 
Posts: 39
Joined: Sun Nov 21, 2010 6:46 pm
Location: Rochester, NY, USA

Re: Common Anode RGB LED Question

Postby adafruit » Mon Nov 22, 2010 12:45 am

common anode are better in the long run - many LED drivers will only work with common anode LEDs
User avatar
adafruit
 
Posts: 10546
Joined: Thu Apr 06, 2006 3:21 pm
Location: nyc

Re: Common Anode RGB LED Question

Postby Alan Chatham » Mon Nov 22, 2010 3:16 am

Hm, just checking out a few datasheets (since I figure one of these days, I'm going to need to use a tri-color LED), and it doesn't look like there's a reliable way to figure out what sort of LED you've got from just the shape of the LED itself (confusingly called the package). Looks like you'll just have to look at the datasheet to get the pinout specific to the model of LED you buy, although with any luck, the bag or box it comes in will have a little schematic for the LED inside, and so you should be able to see from that whether or not it's common-cathode or common-anode.

One quick thing, I feel like I've heard that it's better to sink current to your microcontroller rather than source it (so your LED is on when you pull the pin it's connected to LOW), because the microcontroller is going to be better at letting current flow through it rather than trying to source a bunch of current out of it's different pins. However, I also majored in Economics, so I'm more or less a walking collection of random information and half-truths... Is the 'better to sink than to source' thing correct?
OpenChord.org - Open Source kits to let you play Guitar Hero with a real guitar, or build your own Wii/banned/USB controllers.
Alan Chatham
 
Posts: 143
Joined: Thu Feb 04, 2010 1:30 am

Re: Common Anode RGB LED Question

Postby richms » Mon Nov 22, 2010 3:17 am

KeyboardKowboy wrote:Fantastic. Thanks for the replies. I was hoping that's what was going on.

As for my other question... how would I be able to determine (from the package) that I was buying a common ANODE led and not a common CATHODE led. Anything specific I should look for in the future? Granted I know it doesn't matter much, but I think the code is easier to read and maintain when setting a pin HIGH to turn something on, as opposed to setting the pin LOW to turn certain colors on like in my situation. Thanks again for the help.

(Oh, and I was able to use PWM (analogWrite) to fade in and mix colors... sweet...)


You would need to order from a place that gives you a decent description of what you are buying. Everywhere else will label them as CC or CA or 6 wire so you can tell.

most LED strips etc are common anode, and it makes more sense when you start to drive more LEDs so you need transistors, as you will take the pin high to turn the transistor on, which will then be switching the negative of the LED sinking it to ground.

Also, once you move onto using transistors to sink, the supply voltage becomes prettymuch immaterial, whereas with common cathode you are limited to VCC, unless you start to mess around with 2 transistors etc.

If you want to clean up the code then you can define LEDon as 0 and LEDoff as 1 and use those inplace of 0 and 1 in the code.
richms
 
Posts: 556
Joined: Tue Jan 20, 2009 2:05 am
Location: New Zealand

Re: Common Anode RGB LED Question

Postby KeyboardKowboy » Mon Nov 22, 2010 9:55 am

All great information, thank you.

@Alan Chatham: I'm also intrigued if it's better to sink than to source from the pins...
Memory is necessary for all the operations of reason. --Blaise Pascal
KeyboardKowboy
 
Posts: 39
Joined: Sun Nov 21, 2010 6:46 pm
Location: Rochester, NY, USA

Re: Common Anode RGB LED Question

Postby Entropy » Mon Nov 22, 2010 11:12 am

In general, it is better to sink than source. The nature of transistor device physics means that the transistors required to sink current are much smaller than a transistor needed to source the same amount of current. Conversely, if the transistors are the same size, a chip's sink capability will usually be much greater than its source capability.

Historically this was the case for most microcontrollers, but many of the ATMegas have equal source and sink capabilities due to beefed up transistors. However, most people design circuits assuming greater sink than source capabilities.

There are also other reasons sinking is better - for example, if you want to control a bunch of series LEDs in a strand that are powered from, say +24v, it is MUCH easier to control this with a transistor that sinks current as opposed to one that sources current, since a transistor that sources current will need all sorts of level shifter circuitry to drive it.

People get used to having to invert their logic due to the realities of circuitry pretty quickly. Similarly, many switch inputs to a microcontroller are going to be "active low", where the pin is pulled up to Vcc when the switch is off, and grounded when on, so "1 = Switch Off, 0 = Switch on".
Entropy
 
Posts: 472
Joined: Mon Jan 07, 2008 11:43 pm
Location: Owego, NY USA

Re: Common Anode RGB LED Question

Postby KeyboardKowboy » Mon Nov 22, 2010 1:50 pm

@Entropy: Thanks for that full explanation! I'm glad that my need to "inverse" my logic is a normal occurence. :)
Memory is necessary for all the operations of reason. --Blaise Pascal
KeyboardKowboy
 
Posts: 39
Joined: Sun Nov 21, 2010 6:46 pm
Location: Rochester, NY, USA


Return to Arduino

Who is online

Users browsing this forum: ArekKindAcere, Google [Bot] and 9 guests

Stuff to buy from the Adafruit store and links to product documentation!


New Products [114]

Raspberry Pi[82]
 
FLORA[24]
 
Bunnie Studios[9]
 
FPGA[1]
 
mbed[12]
Arduino[60]
 
NETduino[14]
 
BeagleBone[23]
 
Android[6]
 
XBee[10]
More Dev Boards[30]


 
BoArduino[8]
 
SpokePOV[4]
 
TV-B-Gone[4]
 
MiniPOV[3]
 
SIM reader[3]
 
Microtouch[5]
 
Clocks & Watches[18]
 
Drawdio[4]
 
Brain Machine[1]
 
Game of Life[2]
 
MintyBoost[2]
More DIY Kits[16]


 
MaKey MaKey[3]
 
Tweet-a-Watt[5]
 
Young Engineers[39]
 
Discover Electronics[2]
 
Snap Circuits[4]
 
littleBits[3]
 
Project packs[9]


 
Breakout Boards[35]
LCDs & Displays[49]
Components & Parts[70]
Batteries & Power[54]
EL Wire/Tape/Panel[52]
LEDs[112]
 
Wireless[16]
Cables[66]
 
Lasers[6]
Sensors/Parts[147]
 
Enclosures/Cases[11]
 
Solar[11]
 
RFID / NFC[13]
Prototyping[70]
 
iDevices[13]
Tools[71]
 
Wearables[41]
 
CNC[37]
 
Robotics[29]
 
3D printing[1]
 
Materials[25]


 
Stickers[41]
 
Skill badges[55]
 
Books[26]
 
Circuit Playground[7]
 
Gift Certificates[4]