# Two-wire switch sensor

I've been researching how to design a circuit for a two-wire switching sensor.

It can be operated as a PNP or NPN switch. I need to design a circuit to detect whether the sensor is switched or not.

Sensor specs

The sensor has 1mA current when it's off, and minimum 5mA when on. I'm using 24V.

I think I can design the sensor like this:

I'm going to put a load of 4K ohm:

• off state: V=IR = 1mA * 4K = 4 volt across resistor
• on state : V=IR = 5mA * 4K = 20 volt across resisor

simulate this circuit – Schematic created using CircuitLab

Is that right? But then what is the significance of: internal voltage drop 5V or less? In the off state the resistor would have a voltage drop of 4V which means the sensor will have 20V > internal drop voltage. Will this fry it?

simulate this circuit – Schematic created using CircuitLab

Figure 1. Redrawn schematic. "Chassis" symbol used to differentiate between isolated grounds.

• Off state: V=IR = 1mA * 4K = 4 volt across resistor.
• On state : V=IR = 5mA * 4K = 20 volt across resistor.

Is that right?

But then what is [the] internal voltage drop 5 V or less?

The sensor needs some power to operate. I steals a minimum of 1 mA from the circuit and its internal voltage regulator will drop a minimum of 5 V across it.

In [the] off state the resistor would have voltage drop of 4 V which means sensor will have 20 V [of] internal drop voltage. This will fry it?

No. It is designed to work correctly in this mode.

You can simplify your circuit by driving the opto-isolator directly from the sensor. This is done in most PLCs and has the advantage that you don't have any active circuitry on the "outside" other than the sensor. If you accidentally apply an incorrect voltage only the opto-isolator gets damaged.

The next simplification is to see if you can get rid of the Schmitt trigger. I've shown this on the logic side and you can still use it if you want. It's an unneeded complexity though as most micro's GPIOs have built-in Schmitt triggers.

Now your problem becomes that of finding the correct value for R3. The voltage at GPIO will be a function of IL1, the CTR (current transfer ratio) of the opto-isolator and the value of R3.

Further information:

Does that NPN transistor work as a high side switch? – Dejvid_no1

With only two wires the switch knows nothing about the supply and the load since it has nothing to reference against. It can't tell the difference between being wired with a common positive 24 V or a common negative GND.

What made me confused is that "5 V or less drop" while it can go up to "20 V" when it's in the off state .. thank you for the advice.. im (sic) having 3v3 rail from the 24v rail by switching regulator non-isolated so i dont (sic) need to isolate ground right ?

If you don't need isolation then you don't need an opto-isolator.

simulate this circuit

Figure 2. Since opto-isolation is not required it can be omitted.

I've chosen the divider ratio to make the maths easy. At 20 V out from the switch the 17k and 3k resistors give a 20:3 divider giving you 3 V on the GPIO input. This gives a little safety if the output is a bit higher than 20 V.

• Does that NPN transistor work as a high side switch? – Dejvid_no1 May 27 '18 at 9:44
• well, in the datasheet they say the sensor can be operated NPN or PNP configuration .. – Hasan alattar May 27 '18 at 10:10
• Ah, no problem then. – Dejvid_no1 May 27 '18 at 10:12
• what made me confused is that "5v or less drop" while it can go up to "20v" when its in the off state .. thank you for the advice.. im having 3v3 rail from the 24v rail by switching regulator non-isolated so i dont need to isolate ground right ? – Hasan alattar May 27 '18 at 10:14
• I've updated the answer. Your user profile does not say if English is not your first language. Please use capital letters in the right places. "V" for volt, "A" for ampere, etc., at the start of sentences and for "I". There is no space before a question mark. – Transistor May 27 '18 at 12:34