How to convert a digital signal from 24V to 5V
If this is for an industrial project you are probably better off using an opto-isolator to do your conversion. It provides several benefits.


Current loop on input side is impervious to common mode noise.
Isolated grounding gets rid of loops and different ground level issues.
Galvanic isolation provides protection to both sides.
And of course, the level shifting you asked for in the first place :)








simulate this circuit &ndash; Schematic created using CircuitLab

\$R1\$ should be chosen to establish the appropriate current in the LED at your 24V sensor level.

The size of \$R2\$ will depend on the logic family you are passing this signal to AND the frequency of the sense signal. For CMOS 10K will be sufficiently low, Standard TTL will need a much lower value.