optocoupler PS2501L-1-F3-A
simulate this circuit &ndash; Schematic created using CircuitLab
Figure 1. Proper ways to use the opto-isolator.
This arrangement maintains electrical isolation between the 24 V circuit and the 3.3 V logic.
There is no need to involve the +5 V supply.