My question might be already answered but I have some problem with resolving it. I'm using PC817 Opto-Coupler to turn on a relay. My VCC voltage is about 4.2 volts and the MCU is an STM32F4 with 3.3v voltage level. When I set the MCU pin (M_Relay) low, it seems that Opto doesn't turn on. I measure the voltage of the input diode(Opto input) and it was about 1v which is below the minimal voltage. I'm not sure about what value should I use for R56.
From the data sheet, Forward diode voltage is 1.2V, and it seems to want 20mA.
Thus, the resistor has 4.2-1.2=3.0V across it. For 20mA, Ohm's law says you want 150 Ohms.
There will be some current when you have the input at 3.3V, and it remains to be seen if it's too much for an "off".
You could avoid the issue of the off current by grounding pine 2 and driving the LED from the MCU I/O pin idrectly, if it can provide 20mA (in fact, you'd already be sinking 20mA the way you're doing it now). In that case, the voltage drop across the resistor would be 3.3-1.2=2.1V, and you would use a resistor of 100 Ohms. If the MCU can't do 20mA, you could probably configure the pin as open collector.