Ken Webster says:
Low cost option:
- Pic output through 2.2k to base of 2N3904
- 2N3904 emitter to GND
- 2N3904 collector to relay coil and annode of diode (1N4148 or 1N4001 or similar .. whatever is cheap and/or readily available)
- other side of relay coil and cathode of diode to +9V
To turn relay on: raise output to logic "1", Vdd
To turn relay off: drop output to logic "0", GNDThe 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 |
|
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.