A simple and inexpensive way to switch 24V with a microcontroller is to use the ULN2003 or ULN2803 transistor drivers, which have seven and eight outputs, respectively. These ICs can energize light bulbs or solenoid valves at 500 mA. Damper diodes in these ICs eliminate the need for numerous passive components, especially in designs using coils.
Because of their digital inputs, passive components require numerous parts, complicating assembly, increasing cost, and increasing the need for troubleshooting and maintenance. Few simple ICs can handle more than 24V.
You can connect these devices directly to a microcontroller. If you mount them in DIP sockets, you can easily replace them in case of damage. The circuit uses a 78L05 linear regulator to decrease the power-supply voltage to 5V. The 1N4007 between the 24V dc and the 5V LM7805 regulator protects the circuit from possible power-supply wire reversal. You must take that fact into account in programming your microcontroller because the signals complement the input.