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:
- The sink and source currents specified for the MCU may be different.
- The source current comes from the regulator for the MCU, and this may impose design restriction.
- 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:
simulate this circuit – Schematic created using CircuitLab
Only one of the circuits REQUIRES a series base resistor to function.