Electronic – arduino – Controlling two LEDs with one digital output

arduinocircuit-designled

I have a bicolour RG LED, which looks like this:

RG LED.

I don't have a datasheet for it. There are three cables on it: one is cathode of each colour (common cathode type) and the other two are the anodes of each colour. The forward voltage of each LED is 24V, and forward current is 10 mA.

I want to change its colour by changing ONE digital output of an arduino. I mean that when the digital output is low, green LED is on, and red LED is off. And then when the output is high, green LED should be off, while the red LED is on. Digital output level is 3V DC when it's "high" state, and "0" V DC when it is "low" state.

So, how can I control which LED is on, while changing one digital output?

Best Answer

schematic

simulate this circuit – Schematic created using CircuitLab

Figure 1. High-side driver and inverter.

How it works:

  • If GPIO is low then Q1 is off and Q2 is off. Q3's base will find a path to ground through R1 and D1 and will turn on lighting D2.
  • If GPIO is high then Q1 is on, Q2 is on and D1 will light. Since the collector of Q2 is pulled high Q3's base current will fall to zero and D2 will turn off.
  • By using PWM (pulse width modulation) the light can blend from one colour to the other.

Does it have to be so complicated?

enter image description here

Figure 2. High-side driver fail.

Yes. Without the NPN transistor of Figure 1 there are two problems:

  1. There is a sneak path for the current through the protection diodes of the micro's GPIO. Whether the output is pulled high or tri-stated to try to shut off the PNP transistor of Figure 2 the base can turn on via D1.
  2. The high voltage - 24 V in your case - may damage the GPIO.

Opto-isolator option:

enter image description here

Figure 3. A pair of opto-isolators simplifies the task further and can isolate the 24 V circuit completely from the micro.

  • When the GPIO is low the upper opto-isolatore will be turned on.
  • When the GPIO is high the lower one will be turned on.

The very simple option:

The LED series resistors are clearly visible heat-shrunk in leads of the lamp. If you are prepared to replace these the circuit becomes trivial.

enter image description here

Figure 5. Direct drive of the LEDs.

Setting R1 and R2 to 56 Ω should be fine.

If the output is tri-stated (wired as an input or disconnected by program control) a current will flow through R1, L1, R2, L2 and both LEDs will glow dimly. On a 3.3 V device the voltage wouldn’t be high enough to illuminate both LEDs significantly so they would appear dark.