Is an optocoupler sapposed to act like a switch? 5v on one side and the other side goes close circuit? Or is it that when 5v is applied on one side a voltage is generated on the other side? This is a basic 4 pin optocoupler and I am not clear on how they work.
Basically, voltage on the input powers an LED causing it to emit infrared light onto a phototransistor causing it to switch from a (usually) nonconducting to a conducting state, there are many different types for many different applications. The isolation between input and output can be in the thousands of volts.
In basic terms they act like a one way switch. You need to get the polarity of the output correct for them to be useful
Think of them like the output is a transistor with only a Collector and Emitter, the base is the light intensity from the input LED which provides the isolation