4n25/35 optocoupler detect led on/off

StealthRT

Sep 4, 2010
147
Joined
Sep 4, 2010
Messages
147
Hey all i am just wondering if my drawing below is correct in order to have an arduino detect an on or off led on another board using a optocoupler?

lxtH1.jpg


My thoughts of the above drawing is that when the led is on it will trigger the relay inside and send 5v to the arduino digital pin to read. 0v if the relay inside is not connected.

I also would possibly need to tell the arduino digital pin that its an input pullup like this:
Code:
pinMode(pin, INPUT_PULLUP);
please advise if this is correct or not.
 

Harald Kapp

Moderator
Moderator
Nov 17, 2011
14,271
Joined
Nov 17, 2011
Messages
14,271
There's no relay inside an optocoupler. In this case only a transistor (datasheet). For a typical application see figure 1 in the datasheet. You will need a pull-down resistor to generate a logic '0' in case the LED within the optocoupler is off. A pullup will not help in this scenario.

A better way of using an optocoupler is this:
upload_2017-10-18_8-10-26.png
Beware, this circuit is inverting: an active LED will generate a logic '0' at the output. But this can easily be handled in software on the arduino side. You can also use the internal pull-up of the arduino's microcontroller, so you don't have to provide R2.
Resistor R3 is commonly recommended to reduce sensitivity of the receiving transistor within the optocoupler to noise. A value of 1 MΩ ... 10 MΩ is suitable.
R1 is required to limit input current to the LED. The 4N25 is specified for an LED current of typically 10 mA, max. 60 mA.
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
For the configuration as shown, you need a pulldown resistor.
 
Top