4n25/35 optocoupler detect led on/off

Thread Starter

StealthRT

Joined Mar 20, 2009
303
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?



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.
 

geekoftheweek

Joined Oct 6, 2013
1,219
I am not familiar with Arduino, but I'm assuming the input pullup means it's internally pulled up to your positive supply. If I'm correct then you would connect it to pin 5 and connect pin 4 to ground. When the led is on it will pull down your Arduino pin to 0 volts, and when it is off it will let the pin go back to 5 volts.

I'm thinking if you use a standard input type for your Arduino and add a resistor from pin 5 to ground it may work as you have described. I've never tried it. Without the resistor to ground your input pin will float and may never truly be off.
 

AlbertHall

Joined Jun 4, 2014
12,347
Also you cannot two LEDs in parallel and expect them to work properly. The existing LED will have a series resistor and you need the LED in the coupler via its own resistor across the existing LED plus resistor. The diagram below shows three LEDs but you will have only two.
 

AnalogKid

Joined Aug 1, 2013
11,055
While the output of an optocoupler is a transistor switch, not a relay, your idea is correct. If the input LED of the opto is in parallel with the external LED you want to sense, both will come on at the same time and the opto output will show the status.

BUT

Take Albert's advice. Two LEDs in direct parallel do not behave predictably. Since the external LED is driven by something and has some kind of current limiting, you need to replicate that for the opto LED. Do you have any more information about the external LED you want to sense? What is it a part of, what is the operating DC voltage, is there a resistor in series with it, is it being driven high or low, etc?

ak
 

dendad

Joined Feb 20, 2016
4,478
Yes on both.
Add a seperate LED resistor for the opto and hook the opto pin 4 to Gnd, pin 5 to, for example, Arduino pin 9.
pinMode(9,INPUT_PULLUP);
Pin 9 will go low when the opto LED is lit.

Using the internal pull-ups will save an extra resistor.
Just from memory, I can't remember if all inputs have the PULLUP function available so have a look at the Arduino docs.
 
Top