0
\$\begingroup\$

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: enter image description here

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!

\$\endgroup\$
2
  • \$\begingroup\$ google full-bridge driver circuit. \$\endgroup\$
    – Trevor_G
    Commented Oct 17, 2017 at 20:40
  • \$\begingroup\$ 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. \$\endgroup\$
    – jonk
    Commented Oct 17, 2017 at 20:46

3 Answers 3

1
\$\begingroup\$

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.

schematic

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.

schematic

simulate this circuit

\$\endgroup\$
6
  • \$\begingroup\$ 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.) \$\endgroup\$
    – jonk
    Commented Oct 17, 2017 at 21:42
  • \$\begingroup\$ @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. \$\endgroup\$
    – Trevor_G
    Commented Oct 17, 2017 at 22:17
  • \$\begingroup\$ 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. \$\endgroup\$
    – Irfann
    Commented Oct 17, 2017 at 22:17
  • \$\begingroup\$ @Irfann which opamp r u usung \$\endgroup\$
    – Trevor_G
    Commented Oct 18, 2017 at 0:17
  • 1
    \$\begingroup\$ @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! \$\endgroup\$
    – Irfann
    Commented Oct 18, 2017 at 2:49
0
\$\begingroup\$

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).

schematic

simulate this circuit – Schematic created using CircuitLab

schematic

simulate this circuit

\$\endgroup\$
3
  • \$\begingroup\$ Did you compute the dissipation in \$R_1\$ and \$R_2\$ when the associated nfet is ON? \$\endgroup\$
    – jonk
    Commented Oct 17, 2017 at 21:30
  • \$\begingroup\$ I can confirm - R1 and R2 get smokey when their associated nfet is ON :) \$\endgroup\$
    – Irfann
    Commented Oct 17, 2017 at 22:49
  • \$\begingroup\$ 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. \$\endgroup\$ Commented Oct 17, 2017 at 23:10
0
\$\begingroup\$

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

enter image description here

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:

schematic

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.

\$\endgroup\$
3
  • \$\begingroup\$ 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. \$\endgroup\$
    – Irfann
    Commented Oct 17, 2017 at 22:20
  • \$\begingroup\$ @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. \$\endgroup\$
    – jonk
    Commented Oct 17, 2017 at 22:27
  • \$\begingroup\$ @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. \$\endgroup\$
    – jonk
    Commented Oct 17, 2017 at 22:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.