Wide voltage range input regulation (24V - 3.3V)
My interpretation of your question is:


You want to drive an opto-isolator LED from a digital on/off signal.
High level is 3.3 to 24 V and a low of 0 V.
LED current of 5 mA when on.
Use readily available components.








simulate this circuit &ndash; Schematic created using CircuitLab

Figure 1. A constant current sink.

Opto-couplers use infrared LEDs with a forward voltage of 1.4 V approx. This leaves a couple of volts to work with for our current limiter.


R2 biases Q2 on.
Current flows through D1, Q2 and R1.
When the current reaches 5 mA the voltage at the base of Q1 will reach 0.6 V and it will begin to turn on. This will steal the base current from Q2 preventing further rise in D1 current.




Figure 2. A quick run of the CircuitLab DC sweep indicates that this should work as required.