Will optocoupler work if I use 4.7 k resistance to limit the current to the input of optocoupler from logic supply 3V
Driving the optocoupler's LED with 3.3V and 4.7K for R1 will result in a very low current trough the LED. If we take the PC817 datasheet one can see in &quot;Fig.6 Forward Current vs. Forward Voltage&quot; that for very low currents, around 1mA, the LED's Vf is roughly 1V.
So: $$If = \frac{3.3V - 1V}{4.7K} \approx 0,5mA$$
Looking at figure &quot;Fig.7 Current Transfer Ratio vs.Forward Current&quot; we can see that forward currents below 1mA are marked with a dashed line, presumably to indicate such currents are too low for the device to work reliably.
From the same graph we can see the best current transfer ratio is around 10mA. Looking back at figure 5 we see that for a forward current of 10mA the forward voltage is roughly 1.25V. So we calculate R1:
$$R1 = \frac{3.3V - 1.25V}{10mA} = 205 \Omega $$
Nearest E12 value is 220 ohm.
Of course, do make sure the microcontroller can actually safely source 10mA.
With VCC = 5V and R2 = 4K7 the optocoupler needs to sink
$$\frac{5V}{4K7} = \approx 1mA$$
in order to pull Vout down to ground.
Given the forward current of around 10mA and the typical current transfer ratio at that level this should reliably work with ample margin.