Electrical – Optocoupler with Arduino

arduinoopto-isolator

I'm trying to input 12v into Ardunio Digital inputs. But since Arduino digital input max voltage is 5v, I would like to use an optocoupler as a switch for 12v input into 5v from Arduino itself.

So I have got P621 Opto, But I' little concerned about the opto handle 12V??

Also for optos both in and out can withstand same voltage??

I'm only a beginner since not much able to grasp the tech jargons from the datasheets..

Best Answer

Think in terms of current. You want your input voltage to cause about 10 mA to flow in the LED. The LED will drop 1-2 volts, so (12-2)/0.01 = 1k.

The output transistor will produce a current that you need to convert to a voltage with a resistor. For low speed signals, 10k is a good choice.

Note that this circuit will invert the signal, 12V in will cause a logic zero. This is easily handled in software. Or, you can reverse R2 and Q1 to get a non-inverted signal.

schematic

simulate this circuit – Schematic created using CircuitLab