# Control color of Bi-Color LED using Arduino

I have this push-button switch which has two solder lugs for 12 VDC power and will illuminate red or green depending on the polarity of the wiring. It may not actually use a bi-color LED, but it seems to be a good representation for how it works. I can't find a schematic for the switch, though I expect it may be something like this:

I'm providing the 12V using an LM7812C voltage regulator but I'm struggling to figure out how I could control the polarity of the applied voltage using an Arduino. My idea is to have an Arduino control a MOSFET to switch power to the LED, though I get lost trying to find a way to flip polarity.

Is there a way I could control the LED to be red, green, or off using outputs from the Arduino?

Or alternatively, just have the switch default to one color and switch to the other when triggered by an output from the Arduino?

Thank you!

• google full-bridge driver circuit. – Trevor_G Oct 17 '17 at 20:40
• So it's a single-pole double-throw momentary switch with a bicolor LED (and resistor in series.) Should have five leads, I'd suspect. To drive the LED from a single 12 V rail you will need to place the LED between two half-bridges (UC2950T, for example.) Or just make one up from tiny TO-92 BJTs or mosfets, since you don't really need much current. – jonk Oct 17 '17 at 20:46

You could also do it with minimal components with a suitable dual op-amp configured as two comparators driven by two outputs from the micro.

High on one low on the other would turn on a particular color. Both high or both low would turn it off entirely.

simulate this circuit – Schematic created using CircuitLab

NOTE: R1 here is assumed to be built into the switch so your LEDs don't fry at 12V. But you need to verify what that illumination method really is.

ALTERNATIVE APPROACH: You can also hook the amps up as simple amplifiers with enough gain to drive the outputs to the rails like below. It requires four more resistors but gets rid of some issues with driving op-amps as comparators.

simulate this circuit

• I think a problem here might be related to the difference in voltage at the inputs. Many opamps have differential inputs, which when they get further apart from each other than some tens of millivolts, start sourcing or sinking LOTS of current and become nothing close to ideal, anymore. I've had inputs sourcing $5-10\:\textrm{mA}$ into their nodes. Was that intentional here? (One GPIO will source a lot of current, which will get sunk by the other one, by way of the (+) connections.) – jonk Oct 17 '17 at 21:42
• @jonk I guess that's where the suitable comes in, but I have seen op-amps used as quicky comparators many times. I guess a couple of series resistors would not hurt though. One could also just configure them as amplifiers with enough gain to rail too. – Trevor_G Oct 17 '17 at 22:17
• I appreciate this solution for the minimal parts. I've got it working on a breadboard with a 5V source for my input and it mostly works as intended - The light turns off if both are high or low, and I can switch the color by sending one of the inputs either high or low and leaving the other one open. But if I send one input high and ground the other, or vice versa, the light turns off. – Irfann Oct 17 '17 at 22:17
• @Irfann which opamp r u usung – Trevor_G Oct 18 '17 at 0:17
• @Trevor, Nevermind - I now realize that I connected Vcc to 12V where it should be at the same 5V that the GPIO outputs when high. I'll give this a shot. Thanks for your help! – Irfann Oct 18 '17 at 2:49

If the switch has two leds as drawn and does not include a current limiting resistor, you can connect a GPIO pin to each side of the LED. If both GPIO pins are high or low together, no current will flow and the LED is not illuminated. By making one GPIO high and the second low you get one color; by flipping the values of the GPIO pins you get the second color.

The 330ohm resistor value assumes you are operating the arduino at 5V, and that you are not looking for a lot of brightness in the LEDs.

If there are resistors inside the switch for 12V operation, you will need to use external drivers. The two half-bridge solution suggested by jonk is probably the easiest possibility. Most 12V tolerant peripheral drivers are open collector (they only pull the output down to ground and leave it floating for a high output). If you want to use transistors, put a 100ohm pullup resistor on the output of each of the low-side switches. You will be wasting power on the side that is pulled low, but if efficiency is no critical this will work. Ignore the mosfet part numbers, tiny mosfets will work (or something like a ULN2004 or other bipolar transistors).

simulate this circuit – Schematic created using CircuitLab

simulate this circuit

• Did you compute the dissipation in $R_1$ and $R_2$ when the associated nfet is ON? – jonk Oct 17 '17 at 21:30
• I can confirm - R1 and R2 get smokey when their associated nfet is ON :) – Irfann Oct 17 '17 at 22:49
• I did say it was going to be inefficient, each resistor will dissipate just short of 1.5W when that mosfet is on. This is not a real solution, but should be part of the analysis of options. – Dean Franks Oct 17 '17 at 23:10

You need three states: COLOR 1, COLOR 2, and OFF. It appears that the layout of your switch is:

If you want to use bubblegum parts (cheap, readily available, not special in any way, and supplied by many sources), I'd probably go with four NPN and two PNP, as in:

simulate this circuit – Schematic created using CircuitLab

The advantage here is that it will supply very close to the full voltage across the LEDs in the switch. The disadvantage is the number of parts involved.

A simpler approach using passive high-side resistors comes at a far too great a price, in my opinion. The trade off between very significant voltage loss to the LEDs, extremely high excess wasted currents in the resistors, and gross power dissipation in the resistors (like "watts") simply cannot be made acceptable.

• Thank you for sharing. My original solution was using resistors but the voltage loss resulted in very dim LEDs, as you mentioned. I'd like to try and implement the comparator solution @trevor posted before using the two H-bridges in an attempt to minimize parts. – Irfann Oct 17 '17 at 22:20
• @Irfann That's reasonable. Observe the current load on your I/O pins with Trevor's solution. It's likely to be acceptable. But also significant, too. (But well within the ability of the I/O, I suspect.) Changes could be made to improve that... but then it's more parts again, too. Best wishes. – jonk Oct 17 '17 at 22:27
• @Irfann Also, if you do decide to go with BJTs (I don't expect it, but just in case), you can consider bcv61 and bcv62 since they come in SOT-23 forms, in pairs. So it would require three SOT-23 parts (plus the two resistors.) Some package savings that way. – jonk Oct 17 '17 at 22:35