## Tip - Transistors, Calculate Base Resitance for Simple Switching

Transistors come in very handy for driving external devices that require more than the PIC's 25mA maximum current output. The 2N2222 can handle 600mA continues current, and is very easy to drive with a PIC micro.

Characteristics change between each transistor, and this example is aimed at the 2N2222. There are a couple of things to keep in mind, one being the Gain of the transistor. You want to drive the transistor with about 1/10 of the load current. For example, you have a high power LED that requires 100mA, then be sure to drive the transistor with ~10mA (1/10 of the load current).

To do this, you have to remember that Vbe will always equal ~0.6V. With this in mind, the Base resistor has to drop 4.4V, and remembering OHM's law, V = IR, therefore, R = V / I

R = 4.4 / 0.010
R = 440 Ohm

A 440 Ohm resistor doesn't exist, so use a 390 or 470. Personally I would choose the 470 Ohm, as the base resistor sets the maximum Collector Current (better to have a little more then not enough in this respect). Now that the transistor is setup to drive a 100mA load, but there is one other factor to take into account... LED's are like short circuits when on.

If I try connecting the LED without a series resistor, the transistor will try and drive the current to its maximum gain. This is many times 100mA, so lets put in a little protection. Our supply is 5V, the LED will drop ~2V when on, and the transistor will drop about 1V when on, so our protection resistor will drop 5V - 2V - 1V = 2V. Using OHM's law again, V = IR, therefore R = V / I, so

R = 2 / 0.100
R = 20 Ohm

Once again, 20 Ohm resistors are hard to come by, so go with the next highest value to ensure you won't overdrive your component, in this case the 22 Ohm would be used.

I put together a simple application to calculate the base resistor depending on simple variables, it can be downloaded here