pc817 large emiter collector voltage drop in saturation
To expound further on Trevor's answer: For any optocoupler application you have two circuits to work on. First, ensure that the signal side (infrared LED of the optocoupler) has sufficient current to operate. Then calculate that the driven side sinks enough current to operate the load.

The maximum current \$I_{F1}\$ allowed through \$D_{1}\$ is 50mA (in the datasheet, Absolute Maximum Ratings: Forward current). Choose a convenient value half of that (factor of safety of 2): \$I_{F1} = 20mA\$. Figure 7 from the datasheet shows that forward voltage \$V_{F1} \approx 1.3V\$ if operating at \$I_{F1} = 20mA\$ and ambient temperature of 25C.

Finding for the value for the current limiting resistor for the optocoupler LED:

\$R_{1} = \frac{V_{1} - V_{F1}}{I_{F1}} = \frac{3.3V - 1.3V}{20mA} = 100\Omega\$

Typical 5mm diameter discrete LEDs are driven at 20mA to be "bright enough". Voltage drop across LED load will vary by color so consult its datasheet or this handy chart. Let's assume that \$D_{2}\$ is a green LED that drops \$V_{F2} = 2.0V\$ at \$I_{F2} = 20mA\$. Rearrange your circuit so that \$R_{2}\$ is feeding from positive terminal of voltage source \$V_{2}\$ so that \$V_{E}\$ of \$Q_{1}\$ is conveniently 0V. Given that \$I_{F2} = I_{R2} = I_{C} = 20mA\$, and \$I_{F1} = 20mA\$, Figure 6 gives us voltage drop of \$Q_{1}\$ as \$V_{CE} \approx 1.9V\$. Voltage that \$R_{2}\$ needs to drop is:

\$V_{R2} = V_{2} - V_{F2} - V_{CE} = 3.3V - 2.0V - 1.9V = -0.6V\$

Clearly, we do not have enough voltage to supply the LED!

There are several ways to get around this:


increase \$V_{2}\$
choose a lower drop LED color, or
decrease \$V_{CE}\$ by increasing \$I_{F1}\$ (increasing the base signal to increase collector current)


Assuming we can only change \$I_{F1}\$: choose \$I_{F1} = 30mA\$. Figure 6 now gives us \$V_{CE} = 1.2V\$: so, \$V_{R} = 3.3V - 2.0V - 1.2V = 0.1V\$. That means the limiting resistor resistance is merely \$R_{2} = \frac{0.1V}{I_{F2}} = 5\Omega\$. That's a \$4.7\Omega\$ or \$3.9\Omega\$ resistor if using the E12 series.

Now go back to the signal side and adjust \$R_{1}\$. At \$I_{F1} = 30mA\$, Figure &amp; gives \$V_{F1} \approx 1.35V\$. So \$R_{1} = \frac{3.3V - 1.35V}{30mA} = 65\Omega\$. That's a \$56\Omega\$ E12 resistor.

If you have noticed, we are now operating \$D_{1}\$ closer to its limits. Also if \$V_{1}\$ or \$V_{2}\$ is a battery, we are dropping a lot of energy to waste. If we can minimize \$V_{CE}\$ (and \$I_{F1}\$), we could improve both. One way to do this if your application for the optocoupler is to merely switch on/off the load is to use a FET output optocoupler instead.