# Bipolar Transistor and other stuff

Coming from this experiment, now we want to improve it adding some more electric components.

Infact we know that we cannot draw too much current from the Arduino pins as you can conclude from this wonderful scheme by Pighixxx, or read here. The motor we want to drive is a load that is better not to connect directly to the Arduino board in order to prevent this.

How can we solve this particular problem? We can use a transistor!

Before starting, take a look a this tutorial by Simon Monk taken from the Adafruit website.

## Background

According to what we read in chapter 4 from the book “Practical Elctronics for inventors” by Paul Sherz about transistors, we have to consider some important formulae when we are using a npn one:

Where $H_{fe} = \beta$ (current gain)

We must create these conditions in order the transistor to work:

## Circuit configuration, base resistance

According to this circuit that we want to create, we need to find the resistance value to use with the transistor base. This value is obtained knowing the $I_{b}$ value.

$I_{b}$ is obtained in turn by a second value: $I_{c}$.

We know from the tech specs, that the motor is capable of drawing up to 100mA. So our $I_{c}$ current corresponds exactly to this value. Now, looking at the 2N2222 transistor datasheet, we find a $\beta$ value of approximately 100.

So $I_{b}$ must be 1mA ( $\frac{I_{c}}{\beta}$ ).

How to obtain R now?

At page 153, in section Important Things to Know about Bipolar Transistors Paul Sherz tells us that in order to prevent a transistor damage when working with motors (that are infact inductive loads) we have to connect a diode in parrallel with the motor.

To prevent exceeding $BV_{ceo}$ , which may be an issue if the collector holds an inductive load, a diode placed in parallel with the load will go into conduction before a collector-voltage spike, created by the inductive load, reaches the breakdown voltage.

Here’s also a detailed technical explanation of the diode function by Olin Lathrop:

The diode is to provide a safe path for the inductive kickback of the motor. If you try to switch off the current in a inductor suddenly, it will make whatever voltage is necessary to keep the current flowing in the short term. Put another way, the current thru a inductor can never change instantaneously. There will always be some finite slope.

The motor is partially a inductor. If the transistor shuts off quickly, then the current that must still flow thru the inductor for a little while will flow thru the diode and cause no harm. Without the diode, the voltage accross the motor would get as large as necessary to keep the current flowing, which would probably require frying the transistor.

The motor is partially an inductor. If the transistor shuts off quickly, then the current that must still flow through the inductor for a little while will flow thru the diode and cause no harm. Without the diode, the voltage accross the motor would get as large as necessary to keep the current flowing, which would probably require frying the transistor.

This way we avoid a positive $V_{ce}$ voltage spark to break the transistor.

Everytime the transistor is turned off infact, the motor will create this voltage spark because of its inductive nature and the impossibility for it to have an instantaneus change in current flow.

This spark is dangerous and can damege the transistor, so we need a diode to protect it.

## PWM: what transistor should we use? What diode?

According to the Arduino reference, PWM frequency on most pins is approximately 490Hz. On Arduino UNO and similar boards, pin 5 and 6 have a frequency of approximately 980 Hz.

### Transistor

Is the transistor 2N2222 capable of following this switching rate? Considering different datasheet and also some online discussion, it seems that the 2N2222 can make it! Maybe it will be the case to carefully calibrate min and max PWM value so the duty cycle will fit with the particular rise/storage/fall/delay time of the transistor (if it is the case…)

### Diode

What kind of diode we need if we want to use such a PWM frequency? I’m usign this particular diode: 1N4148. From the datasheet we read that it is capable of a maximum switching speed of 4ns, so I think that it will make it!

## Using a capacitor in parallel with the motor

As Olin Lathrop says, we can use a little capacitor in parallel with the motor to reduce radiation and the speed of voltage transitions:

A small capacitor accross the motor will reduce the speed of the possibly fast voltage transitions, which causes less radiation and limits the $\frac {dV}{dt}$ the transistor is subjected to. 100 nF is excessive for this, and will prevent efficient operation at all but low PWM frequences. I’d use 100 pF or so, perhaps to up 1 nF.

## Testing

Keeping attention to the transistor pinout

and to the diode direction, we create the circuit shown in this Fritzing diagram and schematics

Here the final result. Time to make some test!

Below some data we’ve collected using our very elementary analog multimeter. We measured the base current and the collector current for a fixed value of the Base resistance, slightly varying the PWM duty cycle. Maybe these measurements are not teoretically correct ‘casue the current signal is not a direct one but a time varying one so it will be very appreciated if anybody will let us now how can we improve our workflow in doing this.

Given $R_{base} = 4700 \Omega$, we measure

duty cycle base current (mA) collector current (mA) calculated $\beta$
25% (64) 0.17 20 117
50% (128) 0.3 20 66.6
75% (192) 0.6 65 108
100% (255) 0.8 80 100

As we can see, using a transistor in this particular configuration, we are able to pilot a motor without drawing too much current from the Arduino digital pin.

Here’s the code I have used, substituting the duty value for each measurement:

If you find this article useful and you like it, please leave a comment below: let us know what do you think about it, we'd really appreciate it. Thank you very much and, as always, stay tuned for more to come!