# control 3 leds with one IO using tri-state

I have a small puzzle to solve.

I want to use an GPIO of an MCP23017 I2C IO extender to control 3 LEDs. In the past I have done 2 leds. Output low was green LED, output high was red LED. I simply used 2 LEDs and 2 resistors. One coming from ground to IO and one coming from 5V to IO. When I set the IO to input, there was a small current flowing through both leds.

To solve the leak current, I added a pnp and an npn transistor. This worked like a charm. IO at input was both leds off, output high was red and output low was green. So I had thri states (word joke)

But now...

I'd like to add a circuit with a 3rd LED which goes on when the IO is set to an input. So the circuit needs to detect if the IO is high impedance and turn on an LED.

Unfortunately no good ideas have come to me so far. Does anybody know how such a circuit would look like? (if it is possible ofcourse)

I once did this (kind of) by not setting the pin to input but to pull it up.[sup*[/sup] And I fed this to a transistor. When pulled up the transistor turned on but the led to GND didn't because of the lack of current (voltage will just rise to 0,7V or so). Thing I didn't need though was for the led to turn off when the pin set HIGH. Simply a second led turned on.

But I thing this can be extended by adding a PNP on the high side of that led which will turn off when the pin is HIGH.

• You cant actually have float as a state because it can both float high or float low. Your circuit is simply pulling it somewhere in the middle.

Thank you for your awnser. What do you think of this circuit?

I went out from bc547/6 transistors.

When T1 conducts, the led will be off.

When the GPIO is high, T1 will conduct through the bottom resistor. I calculated the base current at 0.5mA.
When the GPIO is low, T2 will conduct. When T2 is conducting so will T1 (atleast I hope).
So when the GPIO is high or low, T1 will conduct.

But when the GPIO becomes high impedance. T1 cannot draw current from the GPIO. T2 cannot sink current through the GPIO. Perhaps that a current could flow from 5V, through T2, 8600R, 8600R and T1. But the resistance + voltage drop in this line should be to great to allow T2 and T1 to conduct.

I think I made a mistake with the middle resistor of 8600R. This one needs to be lower because the current passes 2 transistors. But other than that I think this could work.

I would place the led just in between the two transistors. Saves you a couple of resistors