Simple Transistor Inverter Circuit.

Thread Starter

ZoNiE

Joined Nov 21, 2016
20
Hi Folks,
I have a valve with two OP821Z photo sensors that are wired in series to 12v. They detect open and closed. They need to be connected to a PLC input. Normally this device has a very expensive controller, and I need to connect them without it. I had been using a similar setup with two PC817 optocouplers instead of relays, but had issues with it being unreliable. This new circuit works, but the problem is that the output is inverted. When the sensors are not blocked, the relays are on. I need the relays on only when the sensors are blocked. I have tried using another transistor to invert this in more than one place, but just cannot get the thing to work. The problem is the minimal current/voltage from the phototransistor, and that I cannot change its configuraton at all. This all has to fit in a very small space as well… I don’t even have room for a DIP to use as an inverter, but am considering SMD dual inverter IC. Would prefer to use all transistors… I'm 35+ years out of electronics school and finding myself rusty as heck as I have not really been designing circuits like this for a living. Any advice to invert the thing without making any changes to the way the two sensors are wired together in the dotted line box would be helpful and much appreciated. They are inside of the valve and I cannot change that.

Screen Shot 2023-03-06 at 5.16.33 PM.png
 

Attachments

crutschow

Joined Mar 14, 2008
34,412
Here's the LTspice of a circuit configuration using the same output transistors, that should work:

The 4N25 opto isolator emulates the photo sensors you have.

When the input current is on (green trace) simulating that the sensor is unblocked, the opto output shunts (shorts) the R1 base current so that the output transistor is off, supplying no current to the relay (red trace).
When the input goes to zero, simulating the sensor is blocked, the R1 current now goes through the base, turning the transistor on and supplying current to the relay coil.

R2 is there to help absorb any leakage current.

Edit: Circuit won't work as shown due to the OPB821Z opto only being able to sink 250μA

1678158176714.png
 
Last edited:

ScottWang

Joined Aug 23, 2012
7,399
I can't find the info about OP821Z on google, when I tried to draw the circuit as crutschow did in post #3, but it seems there are only 4 pinouts, so I tried another way.

The circuit hasn't been tested yet.

Screen Shot 2023-03-06 at 5.16.33 PM_ZoNiE_M1.png
 

AnalogKid

Joined Aug 1, 2013
11,037
I can't find the info about OP821Z on google,
I can:
https://www.mouser.com/datasheet/2/414/OPB820_821-1530422.pdf

Here is the datasheet for the relay:
https://www.mouser.com/datasheet/2/240/Littelfuse_Reed_Relays_HE3600_Datasheet_pdf-876890.pdf

In the TS post #1 schematic, the two opto switch LEDs are in backwards.

You need to add reference designators to each component so we can discuss them clearly. For example, the resistor limiting the current through the two LEDs must be selected to limit the LED current to 20 mA. The 50 mA value you show is the absolute maximum, not the recommended operating current.

At 20 mA input LED current, the output transistor can conduct nominally 250 uA. This is the max current available for driver transistor base current.

You show 5 V relay coils running on 12 V.

Does one end of each relay coil have to be connected to GND, or can they be tied to the +12 V and switched to GND?

Do you have a strong preference for bipolar transistors, or is something like a 2N7000 acceptable. If yes, I would go with one as a source follower. This gets you back to only one transistor per relay, eliminates some resistors, and reduces the relay coil voltage to a more reliable level.

Not wild about putting 12 V on a 5 V component, no matter what the datasheet says. Are you stuck with those exact relays, or can you change to the 12 V version?

ak
 
Last edited:

ScottWang

Joined Aug 23, 2012
7,399
Thanks.

In your schematic, the two opto switch LEDs are in backwards.
That wasn't my circuit, it was from the TS and I just insert two stages of NPN circuits, I thought about the led when it was shown backward, it could be an IR LED and it is really true from the datasheet that you provided.
You need to add reference designators to each component so we can discuss them clearly. For example, the resistor limiting the current through the two LEDs must be selected to limit the LED current to 20 mA. The 50 mA value you show is the absolute maximum, not the recommended operating current.

At 20 mA input LED current, the output transistor can conduct nominally 250 uA. This is the max current available for driver transistor base current.

You show 5 V relay coils running on 12 V.

Does one end of each relay coil have to be connected to GND, or can they be tied to the +12 V and switched to GND?

Do you have a strong preference for bipolar transistors, or is something like a 2N7000 acceptable. If yes, I would go with one as a source follower. This gets you back to only one transistor per relay, eliminates some resistors, and reduces the relay coil voltage to a more reliable level.

Not wild about putting 12 V on a 5 V component, no matter what the datasheet says. Are you stuck with those exact relays, or can you change to the 12 V version?
These are left for the TS.
 

panic mode

Joined Oct 10, 2011
2,740
i am not sure how one can say "this circuit works" unless the goal is that relays act as crowbars. both are shorting 24VDC supply. also the LEDs in optocouplers sloted switches are reverse biased but this was mentioned before.
 

Thread Starter

ZoNiE

Joined Nov 21, 2016
20
Yeah, I just realized the LEDs are in backwards in the diagram, and I intended to have the contacts on the relay close circuit from ground to the PLC input. That was a brain fart. It isn't wired that way.
 

Thread Starter

ZoNiE

Joined Nov 21, 2016
20
Thanks. Tried that, but maybe my resistor values were off. I'll try it tomorrow.
I can:
https://www.mouser.com/datasheet/2/414/OPB820_821-1530422.pdf

Here is the datasheet for the relay:
https://www.mouser.com/datasheet/2/240/Littelfuse_Reed_Relays_HE3600_Datasheet_pdf-876890.pdf

In your schematic, the two opto switch LEDs are in backwards.

You need to add reference designators to each component so we can discuss them clearly. For example, the resistor limiting the current through the two LEDs must be selected to limit the LED current to 20 mA. The 50 mA value you show is the absolute maximum, not the recommended operating current.

At 20 mA input LED current, the output transistor can conduct nominally 250 uA. This is the max current available for driver transistor base current.

You show 5 V relay coils running on 12 V.

Does one end of each relay coil have to be connected to GND, or can they be tied to the +12 V and switched to GND?

Do you have a strong preference for bipolar transistors, or is something like a 2N7000 acceptable. If yes, I would go with one as a source follower. This gets you back to only one transistor per relay, eliminates some resistors, and reduces the relay coil voltage to a more reliable level.

Not wild about putting 12 V on a 5 V component, no matter what the datasheet says. Are you stuck with those exact relays, or can you change to the 12 V version?

ak
I was planning on running the entire thing on 5V with a 7805 but I wanted to ensure enough supply for the two sensors that are oddly wired in series in the valve. I can change to 12V relays. They are less than a buck a piece... Good suggestion on the 2N7000. I'm just using what I have on hand.
 

sghioto

Joined Dec 31, 2017
5,388
What value resistor were you using?
A 5 volt supply is more then enough to power both sensors in series with a 220 ohm resistor.
If you go with the 5 volt supply change R1 and R2 to 4.7K.
1678200461082.png
 
Last edited:

MrChips

Joined Oct 2, 2009
30,795
1678200226607.png

In your diagram, there is no current limiting resistor to prevent blowing the OP821Z and 2N3906.
Also there is nothing to turn off the 2N3906.
 

MrChips

Joined Oct 2, 2009
30,795
In this diagram, R1 and R2 10kΩ resistors are current sources to the OP821Z.
These allow Q1 and Q2 to turn on when the optocoupler is blocked.
Q1 and Q2 turn off when the optocoupler is unblocked.

1678200345645.png
 

AnalogKid

Joined Aug 1, 2013
11,037
In your diagram, there is no current limiting resistor to prevent blowing the OP821Z and 2N3906.
Don't need one, although it is bad design practice not to have one.

By the datasheet, the opto collector current is a nominal 250 uA when the LED current is 20 mA. With no other resistance in the circuit, the output transistor is not saturated, and it limits the driver transistor base current to 250 uA.

Even if you had a particularly hot part, with 10x the stated collector current, this would be only 2.5 mA - still way below the driver transistor's max. base current rating.

ak
 

crutschow

Joined Mar 14, 2008
34,412
10K resistors. What was it doing or not doing?
That resistance is too small since it supplies over a mA whereas the opto can sink just 250μA nominal when saturated.
Since the output transistor needs about 2mA to supply the 24mA relay current, the circuit needs another transistor for added gain (such as Scott's post #5, with a no more than 50kΩ at the opto output with a 5kΩ output transistor base resistor), or use a MOSFET.
 
Last edited:

sghioto

Joined Dec 31, 2017
5,388
That resistance is too small since it supplies over a mA whereas the opto can sink just 250μA nominal when saturated.
Depends on what the saturation voltage is at 1ma. At 250ua it's .4 volts max according to the specs, it may still work. However because of the high gain of the 2N3904 the resistors could easily be changed to 39K with a 470 series resistor for the relay coil.
I actually prefer using a mosfet as well.
1678219002917.png
 
Top