0
\$\begingroup\$

When I am connecting an IO pin of a microcontroller to the base of a transistor, do I need a current-limiting resistor between the IO pin and the base? Or can I just directly connect the pin?

My thinking is that I can just omit the resistor because the microcontroller (attiny85 in my case) has an absolute maximum rating of 40mA sink/source for the IO pins, so it won't supply any more than 40mA to the base of the transistor.

Do I need a current-limiting resistor between base of transistor and IO pin on microcontroller?

\$\endgroup\$
7
  • \$\begingroup\$ I also read here that "You can generally connect the base to a microcontroller’s pin directly without a current limiting resistor because the current from the pin is low enough" but every other source I've read seems to advise using a resistor. \$\endgroup\$
    – eeze
    Commented Feb 9, 2019 at 3:01
  • \$\begingroup\$ I usually put a resistor there. If you have a resistor from emitter to GND, it may not strictly be necessary to put a resistor in series with the base, but I usually do, anyway, just to be on the safe side. For small MOSFET's (BSS138 or 2N7002, etc) I often don't put a resistor in series with the gate. \$\endgroup\$
    – user57037
    Commented Feb 9, 2019 at 3:53
  • 1
    \$\begingroup\$ The reason the author of that page says you can "get away with it" is because a microcontroller I/O pin is really just a MOSFET (high or low side) that acts as if it were a resistor, already. Something on the order of 100 Ohms, perhaps a little less or a little more. However, the reason you still CANNOT get away with it is that there is more than one I/O pin assigned to an I/O port and the port itself has a separate limitation often given in the "ABSOLUTE MAXIMUM RATINGS" heading. The dissipation can fry the port, if you play games like this. "You can be a pig, but hogs get slaughtered." \$\endgroup\$
    – jonk
    Commented Feb 9, 2019 at 3:56
  • \$\begingroup\$ I have accidentally short-circuited outputs for various periods and they USUALLY survive. But I would never do it deliberately. It will certainly not be reliable over the long term in a single sample, nor across large numbers of samples in the short term. \$\endgroup\$
    – user57037
    Commented Feb 9, 2019 at 4:00
  • 1
    \$\begingroup\$ You don't need the resistor if you don't care about your transistor or your microcontroller, but otherwise add the resistor. \$\endgroup\$
    – Hearth
    Commented Feb 9, 2019 at 4:32

2 Answers 2

10
\$\begingroup\$

When I am connecting an IO pin of a microcontroller to the base of a transistor, do I need a current-limiting resistor between the IO pin and the base? Or can I just directly connect the pin?

Yes!

If transistor is connected common-collector no resistor is needed.

if it's common emitter (the more common way they are used) then you will need the resistor,

My thinking is that I can just omit the resistor because the microcontroller (attiny85 in my case) has an absolute maximum rating of 40mA sink/source for the IO pins, so it won't supply any more than 40mA to the base of the transistor.

That 40mA is a promise you must make the the micro-controller, not the other way around.

\$\endgroup\$
3
\$\begingroup\$

When I am connecting an IO pin of a microcontroller to the base of a transistor, do I need a current-limiting resistor between the IO pin and the base? Or can I just directly connect the pin?

The answer is more complicated than a simple Yes/No. It depends on the configuration you use for the interface.

MCU GPIO ports are typically NOT current limited. The specification will recommend the maximum Sink and Source current that your design should limit the current to. There will also be an absolute maximum specified that may include several ports. For example the AVRs used in the Arduino have an aggregate limit for groups of GPIO pins.

Be aware that:

  1. The sink and source currents specified for the MCU may be different.
  2. The source current comes from the regulator for the MCU, and this may impose design restriction.
  3. Sink current does NOT necessarily come from the MCU supply, it may come from another supply within the design.

Here are three general circuits you might employ with a single NPN transistor:

schematic

simulate this circuit – Schematic created using CircuitLab

Only one of the circuits REQUIRES a series base resistor to function.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.