I've read this answer

(reverse function optocoupler) but my case is different:

I've got a CNC mini lathe.

I have a limit switch on one of the lathe's axis ends (X+) wired as NC to my Gecko G540 controller and it works normally. When the switch is closed, the Gecko's input is grounded, the lathe works normally. When the switch is open, the input is not grounded, the lathe halts, for protection. And, if the switch eventually fails, or a wire disconnects, the controller's input will see it as OPEN also and will halt the lathe also. So it's for extra protection.

If I add another switch wired in series with the first, (as in the A picture) for example to limit the movement of the axis to both extremes of movement, it works also normally. If any switch is open, or if any switch malfunctions, the controller halts the movements of the lathe's axis.

But I can't use a switch in one of the lathe's axis extremes. I'll need to use a slot optocoupler.

But I can't figure it out how to do the same thing with the Optocoupler, which will sense the presence or not of the X leadscrew between it's IR LED and it's phototransistor (X+)

If I wire it the way the B picture shows, it's in a normally open configuration. It works normally as the X+ NC Switch. If the led light reaches the transistor it allows the Gecko's input to be grounded. If not, the system halts. If the switch or the Optocoupler fails, the input won't be grounded, and the system will also halt. (Do I need a resistor between the collector and the gecko's input??)

But I want the optocoupler to behave the opposite. When the led light is blocked I want the gecko's input to be grounded, and when the led light reaches the phototransistor, I want to have a high state on the Input. I can't figure how to wire it in series with the physical NC switch (to still use only one input), even with a transistor for inverting the signal, and still mantaining the safety of if any of the switches (opto of physical) fail, the circuit will be open and the controller will halt.

So I'd like the optocoupler to behave exactly as any of the switches on the A picture, but with it's logic inverted. Can it be done in a simple way?

Thanks a lot!


  • \$\begingroup\$ Hi! Thanks a lot!! I understood perfectly your circuit! I’ll try the circuit! But as glenn_gleek pointed out, if the opto-isolator fails, it’ll act as a NC switch, instead of acting as a NO swich... would there be a workaround for this, in case of failure of the optoisolator? \$\endgroup\$ – Rodrigo Apr 12 '19 at 22:11
  • \$\begingroup\$ You've written this a a comment to your question. I presume you meant it as a comment on my answer. I've updated my answer. \$\endgroup\$ – Transistor Apr 12 '19 at 23:19
  • \$\begingroup\$ @Transistor I really made a mistake commenting in my own question! I apologize. I’m having a hard time to visualize your reflective setup. The obstacle is a rotating mettalic screw. But I can’t imagine your setup in my head... \$\endgroup\$ – Rodrigo Apr 12 '19 at 23:32
  • \$\begingroup\$ Why not add a couple of photos of the setup. It's not clear what mechanical problem you are trying to solve. \$\endgroup\$ – Transistor Apr 13 '19 at 7:27
  • \$\begingroup\$ @Transistor ok, I’ll do it later today. I think I imagined your setup and I think it could work. Just a question then. In these type of slot opto isolators, could I “brake” or “bend” it exactly in the middle of the “U”, to make it more like a “V”? Are there components or leads connecting sensor and led in the flat horizontal surface of the “U” slot? Or it’s just plastic connecting both sides? \$\endgroup\$ – Rodrigo Apr 13 '19 at 10:56


simulate this circuit – Schematic created using CircuitLab

Figure 1. The logic of the opto-isolator can be inverted using an NPN small signal transistor.

How it works.

  • When the slot-sensor is obstructed Q2 is off so Q3's base will be fed by R3 and Q3 will short LIM to ground.
  • When light falls on Q2 it will turn on and steal the base current from Q3.

With 1k in there for R3 Q2 will have to pass 5 mA with the amount of light received from D2. You'll need to check the current transfer ratio (CTR) of the slot switch to see if it is likely to be able to achieve this. If not you'll have to increase R3. If this is too much work then just try it as I have drawn it.

In response to comments:

From @glen_geek:

But there are potential nasty failure modes....If any part of the opto-coupler fails, Q3 conducts (acts as a N.C. switch). That's its all OK state.

Agreed. Proving something is absent is much more difficult.

One way around this is to use Figure 1a but cut the slot sensor in half, and make a reflective sensor. The LED light would have to reflect off the obstructing surface into the receiver and then when the reflection is lost Q1 would turn off. This is likely to be difficult to set up. You could try using your phone camera to look at the infrared. (Article by me.)

  • \$\begingroup\$ Yes, that works. But there are potential nasty failure modes....If any part of the opto-coupler fails, Q3 conducts (acts as a N.C. switch). That's its all OK state. \$\endgroup\$ – glen_geek Apr 12 '19 at 21:06
  • \$\begingroup\$ @glen_geek thanks! Would you suggest a workaround in case of failure of the optoisolator? \$\endgroup\$ – Rodrigo Apr 12 '19 at 22:13
  • \$\begingroup\$ @Rodrigo I don't see a workaround - using an opto-isolator in reverse operation is the risky idea...the LED should be viewable by the phototransistor, indicating the "all OK" state. That's the safer way to use an opto-isolator. \$\endgroup\$ – glen_geek Apr 12 '19 at 22:45
  • \$\begingroup\$ I kept commenting on my question... anyway, I think this one (TCRT5000) would work, and I can find it easily here in Brazil. And it would be connected as your first schematics 1A. I’ll try to assemble it and test it. Thanks for all your support! \$\endgroup\$ – Rodrigo Apr 13 '19 at 12:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.