Optocoupler/isolater circuit for 24VDC sense that transfers switch status to 3.3VDC microcontroller
You don't need the R1/R4 divider. Eliminate those resistors and choose a value for R3 that limits the LED current. It looks like setting R3 to 2.2k&Omega; would give you about 10mA maximum through the optocoupler's LED. I didn't look at the 4N25's datasheet...you might be able to go down to 5mA or so.

Note that the logic low voltage into the microcontroller is 1.01V (top picture). That is very high for a valid logic '0' but it might work for some microcontrollers at some supply voltages. I suggest that you delete LED2 and R6. Just use R2 as a 2.2k&Omega; pullup to the microcontroller's supply voltage and connect pin 5 of U2 (the NPN's collector) directly to the microcontroller input pin. If you want to add an LED indicator then use a separate NPN or NMOS transistor for that purpose.