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.

In the left-side schematic in the previous post, I showed R1 at 10K and R2 at 100K. Those values work when the power supply is 24VDC, but what about a BeagleBone Green that toggles between 0v and 3.3v?

Yesterday, I did a series of experiments to see how the BeagleBone Green powers up its GPIO pins. P9_12, the pin that I monitored, ends up at 0v when the board is fully on, but during the power up process, it briefly goes slightly high, about 0.7v. Unfortunately, 0.7v is the threshold voltage to turn on a transistor (and a dimly lit LED showed that the transistor was partially turned on). After trying several different values for R1 and for R2, I found that using a 1k resistor for R1 and a 2.2K resistor for R2 limits the power on voltage to 0.21v (well below the threshold needed to turn on a transistor). That combination also limits the current draw by the transistor to 2.5mA, well below the 4mA maximum per pin for the BeagleBone Green. The 2N2222 transistor only powers an LED at 6.5mA when used with a 220 ohm current limiting resistor, but it is capable of easily controlling a small relay. I have the transistor's connected to one of the BeagleBone Green's 3.3v pins through a Red LED (1.8v drop) and a 220 ohm resistor. The collector could just as easily be connected to a 12v or 24v power rail using a 1k 1/2 watt resistor with a 12v supply or a 2.2k 1/2 watt resistor with a 24v supply. Those values would allow the transistor to supply about 10mA to the LED, which would be similar to the load required by a small relay.