Language: EN


Higher power outputs with Arduino and BJT transistor

In previous posts we have seen how to use digital outputs and PWM analog outputs of Arduino to perform actions in the world.

However, Arduino outputs are limited in both voltage and current. The maximum voltage they can supply will be the supply voltage (5V or 3.3V depending on the model). On the other hand, the maximum allowable current is 40mA, with a recommended value lower than 20mA.

Beyond turning on a small load or running a few sample programs, the truth is that in the real world this is not enough to operate most loads, not even a small DC motor or a relay.

This behavior is common, in general, in all programmable logic controllers. The function of a programmable logic controller is not to provide sufficient current to perform actions. Its function is to read inputs, perform calculations, communicate with other programmable logic controllers, and command actions.

Remember, the processor is the “brain” of a machine, not the muscle.

To perform actions, processors delegate to amplification stages or controllers (drivers), which act as adapters between the power level used in the controller and that required by the actuator.

One of the simplest and most common ways to make this adaptation is the use of transistors. There are two major families of transistors. Bipolar junction transistors (BJT), which were the first to appear, and field-effect transistors (FET).

In this post we will learn to use BJT transistors to handle larger loads than we can handle with the digital or analog outputs of Arduino.

In the next post, we will see how to do this with MOSFET transistors, a sub-family of FET transistors.


Transistors are electronic devices that form the basis of modern electronics. In a very summarized way, we find two different applications or modes of operation.

  • Amplify an electrical signal
  • Act as a switch controlled by an electrical signal

There are many models of transistors, each with different electrical characteristics, to meet the different needs of our electrical circuits. Therefore, an important part of the design phase when using a transistor is the choice of the appropriate model.

Externally the same transistor can be made in different standard packages. Normally, larger packages dissipate heat better and therefore support higher currents better.


The packages we will most frequently use in our projects are the TO-92 and TO-220.

Therefore, it is not possible to easily distinguish the characteristics of a transistor simply visually. We must look at the model number, engraved on it, and consult its corresponding Datasheet.


Transistors are relatively complex devices, and knowledge of electronics is required to understand them in depth. Therefore, instead of performing a detailed analysis, we will limit ourselves to giving a series of guidelines to understand their foundations and to allow us to use them in our assemblies.

If you need more information, you can consult any electronics book, or feel free to leave a comment asking whatever you want.

A good way to understand the operation of a transistor is to look at its “grandfather” in electronics, the vacuum tube.


A vacuum tube is an electrical component that has three terminals inside a vacuum tube. One of the terminals acts as a cathode and another as an anode. The third terminal is connected to a metal grid located between both.

When electricity is applied to the grid terminal, an electric field is generated that “starts” electric current from the cathode. Electrons cross the vacuum, pass without colliding with the grid, and finally reach the anode.

The result is that we have an “electrical contact” between the cathode and anode terminals, in which we can regulate the amount of electricity that flows between both by acting on the grid (the third terminal). With this, we achieve an electrical amplifier.

In BJT transistors, the glass bulb and the terminals are replaced by semiconductor junctions with different levels of doping (hence their name, bipolar junction), forming a solid integrated circuit. This allows them to be much smaller and more durable than vacuum tubes.

In a transistor, we also have three terminals, called Emitter, Collector, and Base. The “electrical contact” we are interested in is made between the emitter and the collector, while the base is the element that controls the amount of electricity that passes through the component.

Operation modes in a BJT


A BJT transistor has three operation modes.

  • Cut-off: In this mode, the transistor behaves as if the collector and emitter were disconnected, so we say that it is similar to having an open circuit
  • Saturation: In this mode, the transistor behaves as if the collector and emitter were connected by a small voltage diode. That’s why we say it’s similar to having a short circuit, with a certain voltage drop
  • Active: In this mode, the current between the collector and the emitter is proportional to the base current

The active mode is the mode used to amplify signals (for example, to make an audio amplifier). In this post, we will not use this mode.

The cut-off and saturation modes can be used together to form an electrically controlled “switch”. It is these two modes that we will use to turn on and off our load, achieving an effect similar to using a physical switch, with the difference that this “switch” will be controlled by an Arduino output.

The state in which a BJT transistor operates depends on the current flowing through its base. For this reason, a BJT transistor is a current-controlled device (in contrast, vacuum tubes and FET transistors are voltage-controlled devices)


There is more than one way to make the transistor connection. In this post, we will use the common emitter configuration, as it is the simplest to switch the transistor.

There are two sub-families of BJT transistors, the PNP type and the NPN type. The difference between the two is the type of junctions and semiconductors used in their manufacture.


Mnemonic rule: You can use the word “Pincha” (which we will abbreviate as “PN”), imagining that the arrow is a needle that pinches or does not pinch the inside of the transistor. If the arrow “Pincha,” it is PNP. If “No Pincha,” it is NPN.

Both types of transistors, PNP and NPN, are similar in constitution and operation, but differ in their application. First, it affects the location where we have to place the BJT transistor in the assembly.


Mnemonic rule: The PNP transistor (P) is placed in the “Positive” part of the circuit. The NPN transistor (N) is placed in the “Negative” part of the circuit.

On the other hand, the NPN conductor conducts when VB is HIGH (greater than VE). However, a PNP conducts when VB is LOW (less than VE). Therefore, the output with a PNP transistor is an inverting output.

Finally, if Vcc is greater than VB (for example, with a 5V Arduino trying to switch a 12V load) we will not be able to switch the transistor because VB will never be greater than VE. And better, because we would put Vcc on the Pin, and we could damage it. In that case, we would need preamplification, for example with an NPN.

Regarding the base resistance Rb, it is used to regulate the current passing through the base of the transistor. The choice of its value is critical for the proper functioning of the circuit. We will calculate the value of this resistance below.

Finally, note that not all transistor models and all packages assign the same terminals to each pin. Therefore, you will have to consult the pinout in the datasheet of the device before making the assembly.


You can automatically perform all these calculations that appear in this section using the BJT transistor as a switch calculator

To use the transistor as a switch, we are going to use the cut-off and saturation regions of the transistor, so we do not have to perform calculations in the active region.

In this way, the calculation is simplified and reduces to calculating the necessary base resistance so that at the desired operating point the transistor switches between cut-off and saturation.

In a BJT transistor, the collector current Ic is proportional to the base current Ib. This relationship is called hFe (sometimes Beta). Typical values are between 100 and 200.

On the other hand, in saturation, the transistor behaves like a diode between collector and emitter with voltage Vce, and a diode between base and emitter with voltage Vbe.

For example, suppose we want to power a load of 200mA with a nominal voltage of 12V, with a certain transistor from whose datasheet we have obtained that

  • hFe(min) = 100
  • Vce(sat) = 0.2
  • Vbe = 0.7

In the example, we assume a constant hFe, but in the real world the hFe relationship varies between transistors of the same model due to differences in the manufacturing process. It also depends on the working temperature and operating point. Therefore, in the component datasheet, you will see curves of dependence of this factor.

Applying Ohm’s law to the device, we calculate that its equivalent is a resistance of 60 Ohms.

Therefore, we can calculate the current flowing through the collector.

The current required at the base is the collector current reduced to a factor of hFe(min), so

Therefore, the necessary base resistance is less than

We choose the lower standard resistance and we would check by looking at the datasheet curves that the base voltage is sufficient to bring the transistor to saturation.

Another way to ensure the saturation of the transistor is to increase the base current slightly. In the example, Arduino has to provide less than 2 mA to the transistor, so we have room to increase the current slightly.

We would choose the nearest standard resistance. In this example, in which we do not have more details about the transistor, a base resistance of 1k would be reasonable.

You can choose the nearest standard resistance with the Standard resistors calculator

Finally, we must check that all elements of the system are capable of supporting the current and power that passes through them (including resistors and the transistor itself)

Some transistor models allow dissipation of higher powers by coupling an external heat sink.


There is a wide variety of BJT transistors that we can use in our Arduino assemblies. In general, they are very cheap components. Their price varies depending on the model and characteristics, but a common price is 0.01 - 0.02€.

Among the many available models, some common ones are N2222, BC547, BC337, BC556, or TIP41C.


When connecting inductive loads, coils, electromagnets, motors, relays, we must put an additional protection device, the Flyback diode.

Inductive loads present a opposition to variations in the current that passes through them, for which they generate an induced current that opposes the changes in intensity. These induced currents can damage the transistor or even the Arduino pin.

The flyback diode provides a low resistance path that allows to dissipate the induced currents by inductive loads, protecting the rest of the devices.


Therefore, in the case of inductive loads, the assembly would look as follows.



To obtain amplification ratios greater than those of a BJT, we can use a Darlington pair, a device based on BJT transistors, widely used in electronics.

Essentially, a Darlington pair is a set formed by two BJT transistors in a single integrated circuit.


The overall behavior of a Darlington pair is similar to a BJT in which the hFEs are multiplied, reaching values of 5000-20000.

On the other hand, the base voltage is added, so the typical values of Vce are around 1.4V.

Similarly, there are multiple models of Darlington pairs. Their price is higher than that of a BJT transistor, but they are still cheap devices. The usual range is 0.10 to 0.20€.

Among the many available models, some common ones are TIP140, BC317, and the ULN2003 integrated circuit, which has 7 Darlington pairs in a single integrated circuit.


BJT transistors are suitable for PWM outputs, so they can be controlled with the analog (PWM) outputs of Arduino.

The result will be a pulsed wave between Vcc and GND, with the same frequency as the PWM.

We just have to check that the switching frequency of the chosen transistor is higher than the frequency of the PWM we apply.


The code to be used is exactly the same as the one we saw when we saw the digital outputs and analog PWM outputs in Arduino, so we refer you to the examples of those posts.

The transistor stage only allows us to adapt the output voltage and current to values higher than we could directly provide with the Arduino outputs.

Download the code

All the code in this post is available for download on Github. github-full