How to use a 24V input sensor (analog) on a microcontroller with 5V maximum input
You can use an optocoupler
Your signal is analog, my bad (thank you @transistor for the comment). (See the edit at the bottom)



simulate this circuit &ndash; Schematic created using CircuitLab
The value of R1 depends on the ptocoupler specifications. The optocoupler is an LED (on the side of the 24V.) If the datsheet says 0.1[A] maximum current to the LED, you do I=V/R =&gt; R=24V/0.1=240 Ohms
EDIT:
You could use a voltage divider to bring down the voltage on the range of 0-5V maximum, and then a voltage follower (using an op-amp) (check Figure 3 is your schematic, really simple). You use voltage follower to not drain any current from the voltage divider, this will mess up the voltage divider circuit.
Then, your 24V will be your 5V (this is your calibration,) your 12V will be 2.5V, and 0V will be 0V.
If you need more accuracy, you can always use an ADC (analog to digital converter) that takes your 24V and gives a 12-bit output (or 8-bit, depends on the ADC accuracy,) usually to I2C line (so you will need to communicate with your ADC with I2C.)