How to choose resistors(RD & RL) for optocoupler circuit
With Vcc = 3.3 V and RL = 4.7 kΩ the required optocoupler output current is ~3.3 / 4700 = 0.7 mA. An EL817 without suffix letter has minimum CTR (current transfer ratio) of 50% at an LED current of 5 mA. Therefore the optocoupler LED current needs to be at least 0.7 / 0.5 = 1.4 mA.
However looking at figure 2 in the datasheet we see that at 1.4 mA CTR reduces to ~60% of its value at 5 mA, so we actually need closer to 2 mA. And CTR also decreases as temperature increases, so to guarantee reliable operation in a hot environment we need even more LED current. Finally, the specified CTR is at a Collector voltage of 5 V. To fully saturate the transistor we need even more LED current again.
How much more? That's a tricky calculation. So let's avoid all that and just choose an LED current of 5 mA (which should be more than enough) and then we can use the datasheet numbers directly. At 5 mA the LED drops ~1.15 V. Subtract this from an input voltage of 24 V and we get ~22.9 V across Rd. 22.9 / 0.005 = 4570 Ω, so we choose the nearest standard value of 4.7 kΩ.
But you are using 2.6 kΩ which should be providing ~8.8 mA, much more than you need. So something else must be wrong. Either the input is less than 24 V, or one of the resistor values is wrong, or the MCU is pulling up internally, or the optocoupler is not meeting its spec. You need to do more measurements to find out where the problem lies.