This mini article provides a small circuit idea to interface a 12V or 24V DC Solenoid (or relay) with a 3.3 or 5V microcontroller’s i/o pins.

24v solenoid/relay interface with microcontroller

Datasheets