Car Speed Sensor with Arduino using Optocoupler or Voltage Divider

I'm working on a project to read the vehicle speed from my car's speed sensor using an Arduino. The speed sensor outputs voltage pulses ranging from 0 to 12V, which the Arduino cannot handle directly.

I somehow managed to get the speed sensor signal wire and checked that with my multimeter, while moving the car the voltage reading changes with max of up to 12v.

Should I use an Optocoupler or a voltage divider

I'm looking for an explanation on how to set up and any tips and code on ensuring reliable readings from the speed sensor. Thanks in advance for your help!

Ranging means they can be anything between. Can they?

I suggest using an optocoupler. Use a 1 kOhm serie resistor to the 12 volt side.
Use INPUT_PULLUP on the input.Don't connect controller negative to car negative!

I would use an opto if the pulse rate is not too high. Do you know that? It is usually stated in pulses per mile (or kilometer).

Maybe neither.
An optocoupler will need a few milliamps of current. Can your sensor source maybe 5mA?

I used my multimeter and measured the voltage

when I start the vehicle, it just shows some milli volts, If I move my car a little bit and further the multimeter shows values 5.1, 7.74, 5.7, 8.6, 3.6, 4.9, 5.3, 10.1, 4.6, 2.8 like that

can you be more specific with a schematic and a code please?

yeah, I checked the current draw of the sensor It's just consuming 2mA

that's why my pc817 optocoupler is not working because the forward current is high (the same value that you mentioned)

Current transfer ratio (CTR : MIN. 50% at IF=5 mA, VCE=5V) - got from the datasheet

can you then suggest some other way please?