convert 12V PWM circuit to 5V PWM using opamp
This is a simple circuit to get the job done. You can use a simple voltage divider followed by a buffer.







simulate this circuit &ndash; Schematic created using CircuitLab

Choose the op-amp, R1 and R2 to suit your application's requirements. I have chosen R1 = 1K, R2 = 1.5K. When the input is 12V, the output is 4.8V. You may find more suitable values to get 5V on the output.

If you use 5V to power the op-amp you may not get 4.8V on the output because op-amp output voltage is never the same as the op-amp supply voltage. Using 12V supply for the op-amp can give you better results.