Optocoupler with Arduino
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.







simulate this circuit &ndash; Schematic created using CircuitLab