Here is an example of circuit using VIshay Optocoupler 4N25

5V to 3.3V GPIO Output (Inverted)

schematic http://www.savagecircuits.com/attachment.php?attachmentid=294&d=1430452949

Logic +5V Input ---> 0.0V output GPIO LOW

+0V Input ---> 3.3V output GPIO High

What happens to the output if my input is -5V???

  • 2
    \$\begingroup\$ Why do you believe that what you already "know" is correct? \$\endgroup\$ – Ignacio Vazquez-Abrams May 25 '15 at 4:00
  • \$\begingroup\$ That circuit does not function the way you describe - it does not invert. \$\endgroup\$ – Peter Bennett May 25 '15 at 4:37

As was mentioned in the comments, what you stated is actually opposite of what the outcome actually is.

When you have an input of 5V, the LED is off, which means no photons to turn on the phototransistor, so the transistor is off. If the transistor is off, then your your output is 3.3V

When you apply 0V to your input, you have current flow through the LED, and photons turn on the transistor, which basically brings it down to ground, so your output is 0V. '

In order to get the optocoupler to behave the way you specified in your description, you need to change where the input is applied. If you make the anode of the LED your input node, and ground the right side of R1, you can get the circuit to work as you described in text.

So what happens when you have -5V as your input ? The thing to know is that when the LED lights up, is when the transistor turns on, and in order for the LED to light up, you need to have current flow through the LED. In this case, you do because the input is at a lower potential than the anode.

However you also have more current going through that branch now and if the resistor is not sized appropriately, you will blow your LED rendering your optocoupler dead.

But what happens if you used the alternate wiring scheme where the input is applied to the anode instead ?

When the input goes -5V, the LED is reversed biased, since the anode is at -5V and the cathode is at 0V. IF the LED can withstand -5V reverse voltage, you are ok. Otherwise, you risk breaking the LED and you now have a dead optocoupler (again).

Looking at the datasheet, the absolute max reverse voltage is 5V, so you are really pushing boundaries, so your circuit may work always, work until it suddenly dies, or just die right off the bat.

  • \$\begingroup\$ I am trying to log +/-5V pulses into its polarity( GPIO0 & GPIO1) If i run a 3.3V regulator first then connected these voltages to to 1x4N25 connected like alternative wiring scheme and another 1x4N25 upside down. That should take care of the max reverse voltage and give me GPIO LOW depending on the polarity. Or is there an easier way by using a zener diode? @efox29 \$\endgroup\$ – Nikola May 25 '15 at 6:47
  • \$\begingroup\$ @Nikola If you keep the circuit as depicted in the schematic, then you won't have any problems. The max current when input is -5V, then the current through the LED is ~8mA and with input as 0V, the current is about ~4mA. Which are both in spec for the opto. So input +5V = 3.3V output and a -5V input = 0V output. \$\endgroup\$ – efox29 May 25 '15 at 6:56
  • \$\begingroup\$ thx bro. im such a newb much appreciate the advice. @efox29 very basic quesion if i apply voltage regulator to get 3.3v out from the 7v. WHat will happen to the -7v will it break my regulator? if so whats the easiest way to get +/-3.3v. I imagine it invovles using didoe with a higg max reverse voltage but then i would need to regulators for each polarity?? After successfully trimming voltages to +/-3.3v can i design 2 comparator to determine polairty and get my approriate gpio output? \$\endgroup\$ – Nikola May 25 '15 at 23:03
  • \$\begingroup\$ @Nikola create a new question. \$\endgroup\$ – efox29 May 26 '15 at 9:08

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.