# Can I use a transistor as a relay with the Pi?

I want to build an electric circuit which has to have a power of nine volts. Can I use a circuit like this, without breaking the Pi? Or is there a better solution?

I would not recommend calling a transistor a relay. While they would do essentially the same thing in this particular case (switch an electrical signal) they're technically different with respect to how they are driven and what kind of signal they switch. I will assume to drive an LED here (joan's answer mentions that additional considerations might be necessary for different kinds of load).

A transistor is a semiconductor device used to amplify or switch electronic signals and electrical power.

https://en.wikipedia.org/wiki/Transistor

A relay is an electrically operated switch.

https://en.wikipedia.org/wiki/Relay

For a bipolar transistor - that is driven by current not voltage - a series resistor between the GPIO pin of the Pi and the base of the transistor is recommended. This is typically around 10 kOhm (see here, R1). Dimensioning this resistor appropriately however requires the specifications of the particular transistor in question and the load it drives. Using the bipolar transistor as a switch (opposed to its use as an analogue amplifier) typically drives the transistor into the so called saturation region - “fully-ON” with the lowest possible resistance across the transistor (and thus the smallest voltage dropout and thermal dissipation). To do this the base resistor is calculated based on the base current required to turn the transistor fully-ON. This minimum base current is calculated from the collector current (the current that drives the load - your LED) and the DC current gain (a parameter obtained from the transistor's data sheet). Learn more.

It is also noteworthy that the limited current a GPIO pin can support (<16 mA) also limits the models of transistors that can be directly driven from the port. For BC547 or 2N3904 driving some LED that should pose no problem.

However, that unsuitable (yet somewhat viral) circuit shown in the question (the emitter follower) has a major drawback: the transistor on the high-side (near the positive supply voltage) is not a useful circuit with an NPN transistor. It will not work of the the voltage drop across the load (the LED) is higher than the voltage level of the Pi's GPIO pin (3V3) which could easily be the case for a white LED. Connect the emitter (the arrow) to ground and put the load (LED) between collector and +20V instead.

One additional thing: due to its non-linear characteristics (I will skip the details that are found somewhere else) the LED requires a series resistor to limit its operating current to a save value. See here.

Conclusion

This is how a simple circuit driving a LED from GPIO pin should look like. Note that selection of transistor and resistor are depending on the current through the LED. Assume GND of the Pi's power supply and the +20V supply are connected. simulate this circuit – Schematic created using CircuitLab

• In the 1950's my father joined a startup called Transistor Electronics that sold a 70 v neon bulb with that circuit. – PaulF8080 Nov 13 '16 at 23:00
• In addition to the comments above, you will likely damage the LED, as an emitter follower will try to put the full 3.3V across the LED, which would result in excessive current. The remaining 9V across the transistor will probably blow it up as well. – Milliways Nov 13 '16 at 23:02
• As an clarification: the emitter follower as mentioned by Milliways is the circuit shown in the question, not the answer. – Ghanima Nov 14 '16 at 8:47

Yes, you can use such a circuit.

Whether it could break the Pi or not would depend on what you are switching on and off. A LED will be fine, a relay coil, motor, or other inductive load, could damage the Pi.