The microcontroller pin: how much can it give?

A GPIO pin is two small MOSFETs inside the chip. At a few mA it is a near-ideal source; as current rises, its voltage sags and it heats up. This chapter shows what a pin really delivers, why power-up is risky, and how to drive a transistor safely.

FundamentalsChapter 04

Inside a GPIO: the push-pull output stage

An output pin is a P-MOSFET to VDD and an N-MOSFET to GND. They are never on together.

  • HIGH: the upper P-MOSFET is on, the pin sources current.
  • LOW: the lower N-MOSFET is on, the pin sinks current.
  • Input: both are off, the pin is high-impedance (Hi-Z).
Animation

Push-pull: sources current when HIGH, sinks when LOW

The dashed frame is the inside of the chip. HIGH: VDD → P-MOSFET → pin → R1 → LED1 → GND. LOW: VDD → LED2 → R2 → pin → N-MOSFET → GND. Copper dots are conventional current.

Output impedance: the pin is not an ideal source

The more current a pin sources, the lower its voltage. The on output MOSFET has a typical RDS(on) of 25–50 Ω.

VOH = VDD − I · Rout Datasheets give it as a guarantee: “VOH ≥ VDD − 0.4 V @ 8 mA”.

At high current the pin behaves like a current source. Into a short it limits at ≈ 50–100 mA, but the pin and chip heat up.

Lab

VOH / VOL vs output current

Model: square-law output MOSFET, 25 °C. 5 V pin ≈ 25 Ω (ATmega328P-like; recommended 20 mA, absolute 40 mA). 3.3 V pin ≈ 40 Ω (STM32-like; spec’d at 8 mA, absolute 25 mA). Use your own MCU’s “VOH vs IOH” graph.

Typical limits and the total current budget

MCUPer pin (abs. max)Recommended / spec’dTotalNote
ATmega328P (Uno, 5 V)40 mA20 mA200 mA (VCC/GND)Port groups have their own 100–150 mA limits
STM32F1/F4 (3.3 V)±25 mA±8 mA (±20 mA relaxed VOL)≈ 80–150 mASeries-dependent; check ΣIIO
ESP32 (3.3 V)≈ 40 mAdrive strength 5/10/20/40 mA (default 20)see datasheetSome pins are boot strapping pins
RP2040 (3.3 V)—drive strength 2/4/8/12 mA (default 4)50 mA (IOVDD)Very low total: 6 pins × 8 mA is already 48 mA

Approximate values; they vary by chip series, package and revision. Check your datasheet’s “Absolute Maximum Ratings” and “DC characteristics” tables. Absolute maximum is a damage threshold, not a target.

Even with every pin within its own limit, the total can exceed the chip’s supply pins.

ΣIpins + Icore ≤ IVDD(max)     Ppin = (VDD − VOH) · IOH
MCUArduino UnoLEDs10 × 20 mATotal limit200 mA
  1. Total pin currentΣI = 10 · 20 mA200 mA
Right at the limit, no margin. Add the core current and you exceed it.

Why you cannot drive a motor or relay directly

Current

A 5 V relay coil wants ≈ 70 mA; a small motor wants 0.5–2 A at start. A pin gives 20 mA.

Inductive kick

A coil’s turn-off spike is pushed through the clamp diodes into VDD. The MCU resets or is permanently damaged.

Voltage

If the load needs 12 V, the pin cannot provide it. The transistor separates the low-voltage control side from the power side.

Noise and ground

If load current returns through the MCU ground, ground bounces. Give load current its own return path.

3.3 V and 5 V logic levels

A 3.3 V output drives TTL-compatible inputs easily, but not 5 V CMOS inputs. VIH is the lowest voltage an input reads as “1”; 3.5 V for 74HC.

Input familyVIH (min)VIL (max)Driven by 3.3 V output?
TTL / 74LS / 74HCT / 74AHCT (5 V)2.0 V0.8 Vyes
74HC (5 V CMOS, 0.7·VDD)3.5 V1.5 Vno
ATmega328P @ 5 V (0.6·VCC)3.0 V1.5 Vmarginal
LVCMOS 3.3 V2.0 V0.8 Vyes
  • 5 V → 3.3 V pin is the dangerous direction: unless the pin is 5 V tolerant (FT on STM32), current flows through the clamp diode.
  • 3.3 V MCU + 12 V load: the pin sees only the gate/base; 12 V must never reach it.
  • The simplest fix is a low-side N-MOSFET with RDS(on) guaranteed at 3.3 V, or a BJT.
  • A 12 V P-MOSFET cannot be driven directly; it needs a level shifter (Chapter 07).

Pins float during reset and boot

During reset and until your first lines of code run, pins are inputs (Hi-Z). With a bootloader that lasts hundreds of ms, and seconds during programming.

Meanwhile the gate floats and picks up noise from wires, the drain (via CGD) and your hand. Near threshold the MOSFET sits half-on: the load twitches and the MOSFET heats in its linear region.

Lab

Floating gate: with and without a pull-down

The noise is illustrative. Model: Vth = 1.5 V, k = 2 A/V², load 12 V / 6 Ω (2 A max). A 10 kΩ pull-down cuts the gate impedance from MΩs to 10 kΩ; with nA–µA of noise current the gate stays < 0.1 V.
Rule: a pull-down on every gate Put 10–100 kΩ from gate to source, on the transistor side of the series resistor. For a high-side P-MOSFET it becomes a pull-up. The same rule applies to a BJT base.
Rs100 ΩPull-down100 kΩ
  1. Fraction reaching the gate100 k / (100 k + 100)99.9 %
The pull-down costs only ≈ 0.1 % of the gate voltage. The gate stays safely off even if the MCU side disconnects.

Open-drain outputs

In open-drain mode only the lower N-MOSFET works. The pin either pulls to GND or lets go; an external pull-up provides HIGH.

  • The pull-up can go to another voltage; 5 V if the pin is 5 V tolerant.
  • Several outputs can safely share one line (I²C).
  • The pin never sources current.
  • The cost: the rising edge is as slow as the pull-up × line capacitance RC.

A series resistor on the GPIO: limiting gate charging current

Put 47–220 Ω in series with the gate. An empty gate capacitance (Ciss) looks like a short at first; only the pin resistance limits the current.

  • It lowers the peak current.
  • It damps ringing on the gate trace.
  • It protects the pin if the gate fails.
  • The cost: the MOSFET switches more slowly (Chapter 09).
Ipeak = VDD / (Rs + Rout)     τ = (Rs + Rout) · Ciss     vG(t) = VDD · (1 − e−t/τ) Because of the Miller plateau a real gate is not linear. This RC model is good enough for peak current and rough timing.
VDD3.3 VRout40 ΩRs100 ΩCiss1.7 nF (IRLZ44N)
  1. Peak without RsI = 3.3 / 40≈ 83 mAhits the pin’s current limit
  2. Peak with RsI = 3.3 / (100 + 40)≈ 24 mA
  3. Time constantτ = 140 Ω · 1.7 nF≈ 240 ns
100 Ω cuts the peak to 24 mA. The gate still charges in well under a microsecond.
Lab

Series resistor and gate capacitance: peak current and charging curve

Same pin model as the previous lab. Datasheet pin limits are DC values; ns–µs charging peaks happen on every CMOS output. At high PWM frequency the average current is f · Qg and the pin warms up.

Clamp diodes, ESD and back-feeding

Drive a signal into a chip whose supply is off and it flows through that chip’s clamp diode into its VDD rail. This is back-feeding.

  • Every GPIO has two ESD clamp diodes: pin to VDD and GND to pin.
  • Above VDD + 0.3 V the upper diode conducts.
  • The “off” chip half-runs, may latch up, or loads your pin continuously.
Animation

Powering an unpowered peripheral through a GPIO

The chip on the right is unpowered. When the pin goes HIGH, current flows through the clamp diode and lifts the chip’s VDD to ≈ 3.3 − 0.6 V. Fixes: do not drive unpowered parts, add 1–10 kΩ in series, or use Ioff-protected parts.
Worked example: 8 LEDs on an Arduino Uno
VDD5 VLED8 red, Vf = 2.0 VR330 ΩPin drop≈ 0.3 V
  1. LED currentI = (5 − 2.0 − 0.3) / 330≈ 8 mApin recommendation 20 mA
  2. TotalΣI = 8 · 8 mA64 mAlimit 200 mA
The 8 LEDs can run straight from the pins. Plenty of margin per pin and in total.
Worked example: a 5 V relay on an Arduino Uno
Coil5 V, 70 ΩPin limit20 mA recommended, 40 mA absolute2N7002 RDS(on) @ 5 V≈ 2–3 Ω
  1. Coil currentI = 5 / 7071 mAabove even the pin’s absolute limit
  2. 2N7002 dropV = 71 mA · 3 Ω≈ 0.2 V
  3. 2N7002 lossP = 0.071² · 3≈ 15 mW
Not directly: use a 2N7002 low-side switch. Add a 1N4148 flyback across the coil and 100 Ω series + 100 kΩ pull-down on the gate; pin current ≈ 0.