From various example on how to use optocouplers ( eg 4N25) I gathered that they work in inverted way meaning that for the optocoupler to output a signal, the input LED must be OFF.

This is very easy to process by code as I just need to use digitalWrite LOW instead of digitalWrite HIGH to activate the output of the optocoupler.

My problem is that when I reboot the arduino, the optocupler LED goes OFF and thus activate the ouput of the optocoupler for a few seconds until the code is loaded on the arduino.

How can I prevent this behavior ? Should I connect the optocoupler in a non inverted way ? ( And if so how ? ). Should I use an inverter ?

  • 1
    An optocoupler has no "default" way of working - inverted or non-inverted. It all depends on how it is wired up. – Majenko Dec 24 '17 at 17:19
  • Thanks for the answer Majenko. It seemed to me that most of the time they were presented as inverted though. Is there a reason for this ? Practicability ? Performance ? Or maybe I got the wrong impression. – CodeFlakes Dec 24 '17 at 18:02
  • What controls optocoupler in your case? electronics.stackexchange.com/a/219882/141930 – AltAir Dec 24 '17 at 18:56
  • Show your circuit or we cannot help you. – Majenko Dec 24 '17 at 21:33

The Fairchild datasheet for 4N25 shows this diagram:

enter image description here

describing the (or 'an') operation of the device. If this is how yours is operating, and if the input side is connected between an output pin and ground, then yes, on reset, the LED will go out and the switched output will go high. If you connect the device's input between the pin and +5v, the LED will light on reset, taking the switched output low. Plus, the switched output will now have the same sense as the Arduino output pin: i.e., digitalWrite(PIN, HIGH) will turn the switched output on, and vice-versa.

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