Drive a relay via a transistor
I've received some questions about connecting a relay to a BOB with transistors. There are two drawings attached that show how easy it is.
One shows a 2N2222 NPN transistor (T1) that drives a relay when the BOB sends a HIGH signal. (Note: The R1 and R2 resistors are for a 12V to 24V input signal. For a BOB, R1 should be 2.2K to 4.7K and R2 should be about 10X the value of R1.) With an NPN transistor, when the base voltage is raised above 0.7V, the transistor begins to turn on. I use a resistor that limits the current to the base to about 1mA or a little less to drive a small relay that has a 10mA to 20mA coil. I also use a second resistor (R2) that is connected to ground to ensure that when the BOB has turned its output OFF, that the transistor will also turn off.
The other drawing shows a 2N2907 PNP transistor that can be used when the BOB sends a LOW (0V) signal to turn a device ON. A PNP transistor starts to turn on as soon as the base is 0.7V LOWER than the emitter's voltage. So pulling the base voltage LOW turns on the transistor. That causes a problem for many people who want to connect the emitter to a higher voltage, such as 24V, but still use 3.3V or 5V to control the transistor. Because the control voltage (3.3V or 5V) is lower than the emitter's voltage, the transistor would never turn off, so two transistors are used. When the BOB sends out a LOW signal, the PNP transistor turns ON, which allows 3.3V to flow to the base of the NPN transistor. That turns the NPN transistor ON. Note that R5 is connected to the BOB's output voltage to ensure that the PNP transistor turns off unless the BOB actively puts out a LOW voltage. R6 also ensures that the NPN's base is low (OFF) unless the PNP transistor is ON.
Both images show diodes connected backwards. Those diodes are needed when a transistor is connected to an inductor, such as the coil to a relay. The diode allows the stored energy in an inductive coil to drain when power to the coil is shut off.
To figure the size of the resistors to use, just use Ohm's law. Voltage / current = resistance, so, for a 3.3V source (3.3V - 0.7V for the transistor) / 0.001A = 2,600 ohms. A 2.2K or 3.3K resistor is close enough. For a 5V source (5v - 0.7V for the transistor) / 0.001A = 4,300 ohms. 4.7K is close enough.
Small signal transistors, like the 2N2222 NPN and the 2N2907 PNP, they have a gain (Beta) of about 100 when the load draws 10mA. That means that the transistor can multiply the current going through the base/emitter circuit by about 100X through the collector/emitter circuit. You could use a much higher resistance resistor to the base, but the values between 2.2K and 10K are customary.
Transistors are cheap, about seven cents each if you buy 100 from Digikey or Mouser. Get a protoboard, some transistors and some resistors and see how easy it is to have your BOB turn things on and off.
|