Opto-coupler circuit - selection of resitor
Follow the next steps:


Calculate the value of resistor R1 (for LED) --> U = I x R --> R = U / I
We know the following things:


Uin = 12 V
Uled (opto) = 1,2 V (take a look into your datasheet)
ILed (opto) = 4 mA (take a look into your datasheet)



So, the total voltage = 12 - 1,2 = 11,8. R = U / I --> R = (11,8 / 4x10^-3) = 2950 Ω
                                                                            = 3 kΩ


Calculate the value of resistor R2 --> U = I x R --> R = U / I
we know the following things:


0.3 V – Saturation voltage of photo transistor (voltage across photo transistor
when current flows through it)
Ic= Collector current (Current flowing through photo transistor when light falls
on it) see datasheet. Let take 1 mA in this case.



So, the total voltage = 5 - 0,3 = 4,7 V . R = (4,7 / 1 x 10^-3) = 4700 Ω = 4,7 kΩ