[Noob question] Can you use an optocoupler to act as a button for input/output?

Hello everyone, I'm new to the world of Arduino and I have this question. Can you use an optocoupler in the same way a push button works but as if it was pushed by the arduino itself or for the arduino? I'll explain my idea.

For input purposes, I wonder if you can have some external voltage source trigger the LED inside of the optocoupler and connect the output side of the optocoupler to a digital pin and ground, so that when the LED will be on, it will be like connecting the digital pin to ground and you can use this in the code as an event trigger or something similar, in the same way you use it with a push button.

For output purposes, I was thinking of connecting the input side of the optocoupler to a digital pin on the arduino (via a resistor of course) and to its ground and the output side to two wires connected to a push button on another device (for instance on a remote controller), so that when the arduino turns the LED on, it will be like pushing that actual button. I know you can do this with a relay, but for such a trivial task and provided that (I think) there's virtually no current flow on the output side, I feel like a relay is completely wasted for such a task.

Sorry if the question might be so "nooby", but I didn't find anything useful online (everytime I search for any optocoupler related task, I end up somewhere where they explain how to use an optocoupler to turn an LED on).

Thank you for your attention

Yes, optocouplers are designed for complete input and output electrical isolation.

You need a pullup resistor between the collector of the optocoupler and Vcc, just like you would with a button connected to ground. 10K, 100K or INPUT_PULLUP should work.

Typical schematic:
Opto.png

I think jremorgan has it backwards. If I read that right, what you want to do is:

  • Use an Arduino output to drive the input of an OptoCoupler [through an appropriate resistance, of course].
  • And, have the output "transistor" of the OptoCoupler take the place of a physical button on something like a remote. That, BTW there will, likely, be NO PULL-UP -- do physical switches have pull-ups?!?.

And, that last point is crucial: The physical "button" to be mimicked [by the OptoCoupler], has different possible configurations. It could be a button with one side connected to the most negative voltage, and a resistor going to the most positive voltage -- and when the button is pressed, it, basically shorts the input (that the button is connected to} to that most negative voltage. OR it could be the other way around [the button shorts the input to the most positive voltage], OR some other strange arrangement.

The electronics going on inside the device you want to control, will, first, need to be figured out [i.e. "reverse engineered" -- unless, of course, you happen to have a schematic].

I'll try to offer more detail, later, but I have something I need to do. But, I wanted to make sure jremorgan's post was challenged. :stuck_out_tongue:

But, the circuit he posted is correct -- but only for certain arrangements on the side of the device-to-be-controlled. And NO PULL-UP!

OK, I'm back.

An example of one of the "other strange arrangements" is: on most remote controls, like for a TV, the buttons are arranged in a matrix. But, you said "remote controller", so very likely, it's a switch with a pull-up or pull-down.

And, come to think of it, yes, you would hook it up just the way you said--probably in most cases--and perhaps in all cases--but, I can't claim to be able to think of every possible case. The output transistor of the OptoCoupler, would go across the switch you are trying to "programmatically" press/toggle/flip. You just need to get the polarity correct -- and make sure the Opto can handle the voltages and currents involved -- but, in most cases, pretty much any Opto will be within range. Possibly the only other consideration is, if the switch is being "scanned", can the Opto output respond fast enough.

AND, you might have better luck with an Opto that uses a MOSFET as the output transistor [rather than a bipolar transistor].

Good Luck!

I think jremorgan has it backwards.

jremorgan sometimes gets things wrong, but jremington's circuit will clearly accomplish this task:

some external voltage source trigger the LED inside of the optocoupler and connect the output side of the optocoupler to a digital pin and ground, so that when the LED will be on, it will be like connecting the digital pin to ground

Where "From_output" is the external voltage source and "To_Input" is the digital pin to be connected to ground.

jremington:
jremorgan sometimes gets things wrong, but jremington's circuit will clearly accomplish this task:

Except that jremorgan's circuit no longer isolates [because both sides of the OptoCoupler are connected to the same ground], and doesn't model the switch [that it's intended to replace] very well. And what if the switch in question, is tied high? And, why the pull-up resistor? The idea, here, is to mimic actual switch contacts. Only the switch is replaced, not any pull-ups, or connections to ground.

Like this:

Thank you guys. I'm slowly learning and understanding.

I would like to accomplish both the scenarios you have shown.

The first one, jremington's one, might be useful to let the arduino know wether something is turned on or off. My idea was to connect the octocoupler in parallel to the power LED contacts (or in its place if the board can't handle the extra current needed by both its own LED and the optocoupler's one) of some appliance I cannot modify too much.

The second one might be useful whenever I want my arduino to push a button for me when a certain event happens. Say I have a light sensor or a motion sensor, like the ones used by common house alarms, and I want my arduino to open my electric gate whenever this sensor is triggered: I wondered if I could just connect two wires in parallel with the button of my RF remote and then connect those wires to the output of the optocoupler. As far as I know, in this cases, many switches connect something to ground and often not much current and not much voltage flows through them (a TV remote often uses 1,5 or 3V and so do RF remotes for electric gates or other appliances or sometimes they use a tiny 12V battery that I guess would never be able to handle such high currents).

Vincintosh:
My idea was to connect the octocoupler in parallel to the power LED contacts (or in its place if the board can't handle the extra current needed by both its own LED and the optocoupler's one) of some appliance I cannot modify too much.

I suggest trying it in series, first. The LED in the typical OptoIsolator drops around 1.1 to 1.3V, so if there is enough "voltage headroom", you might get away with it -- though, in a remote, powered by two 1.5V batteries, maybe not. But, in a Remote Controller for, say a model Airplane--one powered by a 9V battery--or an electronic gate, with a [typical] 12V battery--then there's a good chance that will work. The Power LED might be a little dimmer, though--BUT, the amount of power used, would not increase--in fact it might go down a little.

ReverseEMF:
I suggest trying it in series, first. The LED in the typical OptoIsolator drops around 1.1 to 1.3V, so if there is enough "voltage headroom", you might get away with it -- though, in a remote, powered by two 1.5V batteries, maybe not. But, in a Remote Controller for, say a model Airplane--one powered by a 9V battery--or an electronic gate, with a [typical] 12V battery--then there's a good chance that will work. The Power LED might be a little dimmer, though--BUT, the amount of power used, would not increase--in fact it might go down a little.

That is a great idea aswell... I'm slowly gathering informations for a future project eheh thank you very much

I try to mimic a push button with an optocoupler as well. But it just doesn't work as a "real" push button.

As you can see in the schematic. The optocoupler should connect another resistor in parallel to a existing resistor.

Scenario 1:
Optocoupler is not connected to power.
The resistance on the output is 220 Ohm.

Scenario 2:
Optocoupler is not connected to power.
I make a shortcut between emitter and collector.
The resistance on the output is 211 Ohm.

Scenario 3:
Optocoupler is connected to 3.3V power. And removed the shortcut.
The resistance on the output is 1900 Ohm Ohm.

So the Optocoupler has a internal resistance of around 3000 Ohm. Is that normal?

How can i make it that the optocoupler acts as a "real" pushbutton without internal resistance?

My aim is to connect the output to the audio jack of a smartphone and send a volume-up when the optocoupler gets power from a PIR sensor.

I am getting this error when i try to upload a attachment:
There was a problem during the uploading of IMG_20191123_185931.jpg.
Your post has been made, however the above attachment was not attached. Please use the Back button to edit your post and submit any required changes.
Your attachment has failed security checks and cannot be uploaded. Please consult the forum administrator.

EDsteve:
How can I make it that the optocoupler acts as a "real" pushbutton without internal resistance?

You would need an optocoupler whose output device is a FET, not a bipolar transistor.

No, I don't know of any offhand.

@Paul__B Thanks for your reply. I am really stuck with this little project :frowning:

Maybe there is another solution besides optocoupler?

Problem:
A PIR sensor should switch two resistors in parallel. So that a smartphone get's a Volume_Up signal through the headphone jack.

Look for a miniature 5 V reed relay. If it requires less than 30 mA, you can drive it directly from an Arduino output.

You can get slotted opto couplers, then you just interrupt the beam and you have a switch function. My suggestion is to start with this link, it will give you some of the basics. It will also help you better format your question but I think you will figure it out: https://www.electronics-tutorials.ws/blog/optocoupler.html
This response is to help you get started in solving your problem, not solve it for you.
Good Luck & Have Fun!
Gil

Last night in bed i actually had the idea to make a coil and put it in front of a reed switch. So i guess that's similar to a reed relay :slight_smile:

I will look into both solutions. Thanks @gilshultz and @Paul__B

gilshultz appears to be responding to the OP of some 14 months ago, with no relevance to Ed's problem.

You can't measure the conductance of a transistor with an Ohm meter. What did it read with the probes reversed?