3 color LED via Arduino - how?

Heya all,

So I've got this 3 color LED. It appears it has a common positive anode and then 3 different cathodes, grounding any one of them gets you blue/red/green.

Since the Arduino can't 'toggle' the ground pins at all (at least that I understand?) I can't figure out how I can drive this LED via "analogWrite" or "digitalWrite" since that just controls the positive current on/off/analog values on the various pins.

I'm sure there is an easy solution that I just don't have the experience to figure out.

I'm betting something with transistors opening/closing a path to ground for each cathode? But how exactly would I breadboard that up?

I've yet to figure out how to use transitors in simple circuits, I always end up using reed relays when I need to turn on/off devices with only low current to work with, even though I know that's really the realm of a transitor. Er, I think?

Thanks in advance,

JD

Connect the common anode to 5V, connect each color to a PWM pin through a 220 to 470 Ohm resistor, then:

analogWrite(pin,255 - value);  // to fade

Or:

DigitalWrite(pin,LOW); // to turn ON
DigitalWrite(pin,HIGH); // to turn OFF

Since the Arduino can't 'toggle' the ground pins at all (at least that I understand?)

Yes it can, it can switch a pin between 5V ans ground.

You need to keep the current below 30mA otherwise you need a transistor to get more current.

Thanks to you both...is there some special pinMode command in setup to make the pins act as a ground rather than a positive source? Or will they 'detect' the incoming 5V and somehow automatically flip to ground?

Sorry, noob questions, if there is a specific tutorial I should be reading, I couldn't readily find it, most Google searches just get all kinds of standard LED situations explained...nothing about this reverse polarity type aspect...

JD

Think of an output pin like this, when HIGH, it's connected to Vcc, when LOW, to GND.
outPin-1.png

is there some special pinMode command in setup to make the pins act as a ground rather than a positive source?

No they act as both a source and a sink, high a source, low a sink.

outsider:
Think of an output pin like this, when HIGH, it's connected to Vcc, when LOW, to GND.
outPin-1.png

This won't work, because the anodes of the three LEDs are tied together.
Try this (the values are estimated and might not be correct for your application):

This will also work with the Data pins, as well.

Fensty:
Thanks to you both...is there some special pinMode command in setup to make the pins act as a ground rather than a positive source? Or will they 'detect' the incoming 5V and somehow automatically flip to ground?

Sorry, noob questions, if there is a specific tutorial I should be reading, I couldn't readily find it, most Google searches just get all kinds of standard LED situations explained...nothing about this reverse polarity type aspect...

JD

Problem is, I can't fathom what you're talking about. It sounds like you have an incorrect understanding of how this works.

When you set the pin mode to OUTPUT, i.e. like this:

#define DA_PIN 6  // Label Pin 6 as "DA_PIN" -- The choice of pin 6 is arbitrary.
pinMode(DA_PIN, OUTPUT);   // Make Pin 6 an Output

The pin becomes an output that can be used to "drive" things by setting the output to either HIGH or LOW.

When you digital write a LOW to this pin, like this:

digitalWrite(DA_PIN, LOW);

pin 6 is pulled to ground. In other words, anything connected to the pin is, essentially, connected to ground.

When you digital write a HIGH to this pin, like this:

digitalWrite(DA_PIN, HIGH);

pin 6 is pulled to +5 [unless this is a 3V Arduino, in which case it's pulled to +3v]. Again, the pin is, essentially, connected to the +5V supply.

These "connections" are limited: for instance, trying to draw more than 40mA through them can damage them. And, I like to limit that to around 20mA.

There's more, but I don't have time to write a textbook ;).

I suggest you check out the various sites that teach electronics, like https://www.allaboutcircuits.com/

Here's how to do it with bipolar transistors -- only really needed if currents higher than 20 to 30 mA needed to be switched -- which is not really the case, here, but it shows the technique:

And, here it is using MOSFETs [almost always the better choice]. There are other MOSFET driving considerations, but for simple, low frequency switching, this will do the job in most cases: