Setup (not strictly necessary to answering the problem; supplied for the curious): I have a single logic output pin from a device, logic 0 = 0 V, logic 1 = pulled high to Vcc through a 10 kΩ resistor. I want to use a bicolor common cathode LED to indicate its state: logic 0 = green LED on, red LED off; logic 1 = green LED off, red LED on. I could accomplish that alone easily enough (in fact, it's just a driver for the red LED, and an inverter/driver for the green one).

The complication is that I want both LEDs off if the input is disconnected from the device's GPIO pin, i.e., I want green to indicate only "true 0" and red to indicate only "true 1".

So the desired truth table is (Z = input disconnected from device):

in G R
0  1 0
1  0 1
Z  0 0

Anything I can think of tries to pull the input both high and low to accomplish the "default" state; of course, it's not possible to do both at the same time. A solution with a couple of transistors would be best, but I'm not opposed to something more involved.


2 Answers 2


Here is a simple circuit that will do what you are asking and meets the "common cathode" constraint. Three or four parts if you use a >4 or 4-resistor array. It uses a very inexpensive LM358 dual op-amp as a dual comparator (not generally advisable but fine in this case).


simulate this circuit – Schematic created using CircuitLab

If you modify R2, R3, R4 you can get closer to whatever your logic considers "true" 0/1. In this case, the thresholds are 1/3 and 2/3 Vcc, so very reasonable (but not bulletproof) for a CMOS input.

Simpler circuits may be possible if you could use two discrete LEDs and are not too fussy about where the thresholds fall.

  • \$\begingroup\$ Thanks so much to Spehro Pefhany and @citizen. Sounds like the consensus is to create and detect a half-way-between-0-and-1 state that the connected device will override but that can be detected until it does. On the up side, I guess I'm not a complete idiot for overlooking a simple, 2- or 3-transistor logic solution! \$\endgroup\$ Jan 6, 2023 at 22:33
  • 1
    \$\begingroup\$ @Arby Bellie. Yes that's the gist of it. I'm sure you can refine it even further to suit your application's needs. BTW since you seem to agree to our valuable suggestions it might be equally curtious for you to provide us both with your positive feedback ;-) \$\endgroup\$
    – citizen
    Jan 9, 2023 at 8:29
  • \$\begingroup\$ I agree! And I tried! But I just joined, so the board wouldn't let me. ;( Please accept my secret +1s for each of you! \$\endgroup\$ Jan 9, 2023 at 10:28

There may be various ways to achieve what you are trying to do, but one of the most straight forward ways is to employ two comparators on your input that detects voltages "outside" the logic threshold zone of your logic gate input. Say, if one comparator detects a level < 0.7xVcc and the second comparator detects an input voltage > 0.3xVcc then you consider your input NOT to be of a logic level, and rather some "Z", otherwise it IS a "true" logic level and everything stays normal. When this "other" condition is met then you switch off your Vcc to the LEDs to keep them off. There may be other simpler ways or less costly, to go about it, but the principle is that that your "Z" condition is that zone of voltages that does not normally correspond to your expected logic level thresholds. The "Z" input condition will require setting a suitable bias input voltage (say 0.4xVcc or other similar), but this will be driven true high/low when ever there is a true logic input. You will of course need to keep your logic from getting in a saturated state (or eliminate the logic gate completely), but this you may need to figure out the best way to do ... Hope this helps to get you going.


This site is temporarily in read-only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .