# Tri State/Floating Signal Detection

I'm working on a project for automotive environment in which I need to read signals from the power mirrors switch in a microcontroller. The power mirrors switch controls the mirror's moving directions by connecting VCC (12v) and GND to some wire while leaving the others opened. As I need the microcontroller to know which mirror is moving and what is the direction, it needs a circuit to convert the signals from the power mirrors switch (12V, GND or high impedance) to two logic level signals (5V), for example, one to indicate VCC, another to indicate GND and if both are off it means high impedance. In other words, the circuit needs to be able to detect high impedance or tri state. I have stupidly thought of the following circuit using optocouplers:

It seemed fine, because if the input was high, the output of O1 would be gnd, activating the VCC sinal in the microcontoller (pull-up resistors turned on in the microncontroller inputs); if the input was low, O2's output would be on and it would activate the GND input in the microcontroller; and if the input was opened, none of the optocouplers would be activated and the microcontroller would know the signal is high impedance. It seemed fine until I found out in practice it was a silly idea: what happens is both optocouplers stay on when the input is opened or high, because current flows from O2 12V to O1 GND, keeping both LEDs turned on.

I wonder if someone knows a circuit that can do this job, with the smallest possible number of components, considering I don't have much space for implemanting it.

Thanks in advance for any help!

UPDATE

As said by @brhans in the comments, this circuit works for detecting tri state, just not the way I thought at first. When the input is opened, both optocouplers activate; when the input is VCC, O2 turns off while O1 keeps activated; and when the input is GND the opposite happens, O2 keeps activated while O1 turns off. So all I had to do was adapt my microcontroller logic for this situation.

Thanks @brhans for the hint and also thanks to all who sent other circuits suggestions!

• Why is it a problem that both opto's turn on with a high-impedance/open-circuit input? Your micro will just see both inputs as active, and interpret that accordingly. Sep 27, 2019 at 18:16
• Can you add a schematic of the actual mirror circuit? You can add one in using your own schematic editor or the CircuitLab button on the editor toolbar. Double-click a component to edit its properties. 'R' = rotate, 'H' = horizontal flip. 'V' = vertical flip. Note that when you use the CircuitLab button on the editor toolbar and "Save and Insert" on the editor an editable schematic is saved in your post. That makes it easy for us to copy and edit in our answers. You don't need a CircuitLab account, no screengrabs, no image uploads, no background grid. Sep 27, 2019 at 18:32
• You would need a circuit before the opto to detect the high impedance state. Since you don't have room, probably best to ditch the opto if you actually do need to detect tri-state Sep 27, 2019 at 18:46
• @brhans you're right! Just fixed my micro logic for seeing the tri state when both inputs are high and it worked fine. This is one of those moments where you look at something so much and don’t realize the obvious solution right in front of you. Thanks!
– Roga
Sep 28, 2019 at 17:14

While waiting for clarification to my comment in your original post, is this what you want?

simulate this circuit – Schematic created using CircuitLab

Figure 1. Connect the two opto-LEDs back to back.

How it works:

• In the tri-stated condition neither conducts. About 6 mA flows continuously through R1 and R2.
• When SW1 is pressed 12 mA flows through D1 and R2. (With 1.5 V across D1 a further 1.5 mA will flow through R1.) D2 is reverse biased but with only 1.5 V across it no damage will result.
• With SW2 closed the situation is reversed and 12 mA flows through R1 and D2.

It uses the same number and values of components as your original design.

• This would be a dangerous thing to do, since in the unlikely event that SW1 and SW2 both close, you're shorting 12V to ground and are likely to burn something. Dec 8, 2020 at 16:28

If you would prefer to eschew optoisolators, you could use something like this circuit. Q1 collector goes high for input low, Q3 for input high and both are low for input floating This takes 3 transistors and 2 4-resistor networks. Add E-B diodes if you want to make it more bulletproof against large transients.

simulate this circuit – Schematic created using CircuitLab