A Vishay opto-isolator (CNY74-4) that takes input from buttons that work on 24V, and outputs to microcontroller pins (an ESP32 in my case).
A ULN2803 darlington array connected to the microcontroller, +24V and GND, driving LEDs.
Initially I had designed the circuit so that the 24V of the buttons had its own separated GND. But to use the ULN2803, I need to connect the GND of the microcontroller to the GND of the 24V power supply, or it won't work.
This entire setup works perfectly, but I'm wondering if I should also put an opto-isolator between the microcontroller and the ULN2803. It might be overkill, but then the 24V power supply is completely separated electrically from the microcontroller.
I discovered the Vishay ILQ30, an opto-isolator with darlington output. It could take care of this in one DIP. Or the Toshiba TLP627-4, that one is in my KiCad library
What is the application?
The mention of 24V rings of an industrial use.
Most PLCs use opto isolation on their digital inputs like you have, it is a very good move in an environment that could have all sorts of noise and voltage spikes.
Most PLCs also opto-isolate their outputs for the same reason.
So if you have the room and hardware and need that level of protection, go ahead, it is a regular practice.
There are circuits to isolate analog inputs and outputs, but they get very complicated and expensive.
It could protect the microcontroller from 24V if the ULN2803 burns-up and shorts-out but that's unlikely to happen just driving LEDs and the microcontroller might survive anyway because the current-limiting resistors for the LEDs will limit the current into the microcontroller.
If you had a "user connection" where something is likely to be mis-wired an opto-isolator might be a good idea.
Your circuit is fine without the proposed isolator. I do question using a ULN2808 for only 1 input / output. A MOSFET would have done the job, only 3 connections and no connections spare to worry about.
It would be preferable if you draw a schematic with everything connected rather than have a search-a- word schematic.
Also including the LEDs and buttons and power supply.
The circuit you have supplied is okay for PCB production, but not good for any signal tracing and troubleshooting.