Relay / Solenoid IO Driver:

Lowest Cost for Higher Voltage coil

Ken Webster says:

Low cost option:

To turn relay on: raise output to logic "1", Vdd
To turn relay off: drop output to logic "0", GND

The diode shunts voltage overshoot from the coil's inductance when the transistor is switched off and prevents damage to the transistor.

You can substitute similar transistors for 2N3904 if available or cheaper: 2N2222 is a close substitute

            +24
             |
             |---------,
           relay       ^
            coil     diode
             |---------'
           drain
  +5  --- gate      N Channel Hexfet
 control   source
             |
            GND

  • Very low parts count
  • Good for high voltage relay coils
  • Good for high current relay coils
  • High impedance input

Select an enhancement-mode N-channel MOSFET or HEXFET which completely turns on at 5 volts (such devices are often referred to as "logic level" FETs). Choose current and voltage ratings larger than your relay coil requires. An inexpensive device capable of driving 1A at 100V is the IRLD110.

Add a reverse biased diode across the relay coil to protect the driver. Any diode with a current rating higher than the current of the coil and a voltage rating higher than the voltage of the coil may be used. 1N4001 is a low-cost diode suitable for most applications.