Prevent two opto-isolators to be on at the same time

I have a heat pump with almost no control (except the temperature) and I'm turning it into a smart one by simulating it's button presses (I need it to switch it's operating temperature depending on if I'm heating my floor or DHW).

Anyway, I diverted it's buttons to opto-isolators so I can simulate button-presses. All buttons have a common ground. I control the opto-isolators with a shift register.
Everything works fine, except that I noticed that if I press both "down" and "up" buttons at the same time, my heat pump changes into "cooling mode", which would be catastrophic e.g. at night mid-winter.
Both buttons should In theory not pressed, but if a wire gets loose or anything, I can't 100% trust the shift register (or there could be a bug in my programming, for example).

Is there a way to 100% prevent both buttons (optocouplers) to be on at the same time. Perhaps an electronic element that would "mechanically" prevent that... Just to have a redundant fail-safe?

(I'm attaching an approximate scheme of the situation)

cool_schem.png

cool_schem.png
How about a Xor-gate taking input from the pins and providing output to one of the opto-couplers ? If both pins go high,that opto-coupler gets disabled. 74xx86, not the most common one available, but you should also be able to build one from a few NAND gates (nearly all gates can be build by using 1 to 4 NAND gates.)

Oops sorry this is not quite correct, since if the directly connected pin goes high while the other one is low that optocoupler gets triggered. let me play with some NAND gates i''l get back to you.
2 input exclude with NAND.JPG
Think i've done it using 3 NAND gates, check my truth table, i don't do this every day. You'll have to make the optocouplers active Low but that shouldn't matter

2 input exclude with NAND.JPG

For an absolute guarantee use a relay with SPDT contact arrangement. It is physically impossible to "Press" both at one time (unless you smash the relay with a hammer).

Just write the code that drives the opto couplers defensively, turning off all the opto-couplers first,
then selecting the correct one to drive on, then driving it on and return. Ensure it won't do anything
if called rapidly in succession with different values (record the time it was last used and return a
value to say "not ready yet")

Then write a test harness and hit it with random calls, while monitoring a set of LEDs driven by
the pins.

Then you can convince yourself its solidly working.

Thanks for the help! What if I used a CD4051BE demux? There is no chance of two output pins being high at the same time, right?
I used the shift register, since I need to control four buttons, but I control other things with the other 4 pins (water valve,...). But I could wire a demux after the shift register and control the demux with the shift register, right?

6hearts:
What if I used a CD4051BE demux? There is no chance of two output pins being high at the same time, right?

Yes, that would do it.

However, you said

6hearts:
Everything works fine, except that I noticed that if I press both "down" and "up" buttons at the same time, my heat pump changes into "cooling mode"

Do you not want to be able to use cooling mode in summer?

An alternative approach would be to monitor the output of the system to see if it heating or cooling and if what is coming out doesn't match what it is supposed to be doing then take some action to change the output.

I had a similar problem with my heating controller, which has taken me 30 years of development, in that I needed to be sure that the boiler could not start if there were no motor valves open. In this case there are contacts in the valves that close when the valves open, so the boiler start signal is wired through them.

6hearts:
Is there a way to 100% prevent both buttons (optocouplers) to be on at the same time.

Yes.
The two opto LEDs in parallel but opposite (like a bi-colour LED), with one current limiting resistor.
Connect that circuit between two pins of the 74HC595.
Leo..

6hearts:
What if I used a CD4051BE demux? There is no chance of two output pins being high at the same time, right?

Well, a CD4051 is actually a pretty bad choice for this function and the proper HCMOS version only marginally more appropriate. The "CD" version has a nominal switch resistance of 125 Ω at the maximum 18 V supply voltage; it would be significantly worse at 5 V while the 74HC4051 is 80 Ω. The Arduino has an output resistance of about 40 Ω but is actually specified to drive 20 mA, the sort of current you want to drive an opto-coupler, unlike these other chips which are not.

You need to develop the mind-set that the CD4000 series are essentially obsolete for digital switching at 5 V or 3.3 V - but still useful for analog signal controls such as audio where you use them in conjunction with op-amps. Elsewhere I have been pointing out - against some resistance - that the older "7400" series of logic gates are really obsolete.

6hearts:
I used the shift register, since I need to control four buttons, but I control other things with the other 4 pins (water valve,...). But I could wire a demux after the shift register and control the demux with the shift register, right?

Sounds rather confused.

Wawa:
The two opto LEDs in parallel but opposite (like a bi-colour LED), with one current limiting resistor.
Connect that circuit between two pins of the 74HC595.

Now that approach is a really elgant solution to your unfortunately mistaken requirement - as pointed out in reply #4.

Wawa:
Yes.
The two opto LEDs in parallel but opposite (like a bi-colour LED), with one current limiting resistor.
Connect that circuit between two pins of the 74HC595.
Leo..

DAMN! I wish I'd thought of that! :slight_smile: