What a pin can and cannot do
You have two motor circuits on the bench — one straight off a GPIO, one through a transistor. This is how to tell which is right, before you power either one up.
Where this is going. Lesson 01 explained what the flyback diode is for. This one explains what it isn't for — and why your direct-to-GPIO motor would still be a problem even with a perfect diode fitted.
Here is the trap in your question “why one over the other”: it assumes the transistor and the diode are alternative answers to the same problem. They are not. They answer completely different questions, and a circuit driving a motor has to answer three of them.
Miss any one and the circuit fails — but it fails in a different way each time, which is why swapping parts at random so rarely fixes anything.
Gate one — current
Can the pin supply it?
A GPIO pin is a tiny switch inside the chip, connecting the pin either to 3.3 V or to ground. Like any switch it has a current rating, and Espressif publishes it.
ESP32 Series datasheet, Table 5-3 (DC Characteristics) and Table 5-1 (Absolute Maximum Ratings).
| Drive strength, sourcing | 40 mA | high-level, VDD3P3_CPU / RTC |
|---|---|---|
| Drive strength, sinking | 28 mA | low-level |
| Output high level | 0.8 × VDD | ~2.6 V from a 3.3 V rail |
| Cumulative IO current | 1200 mA | absolute max, all pins together |
| Absolute max pin voltage | 3.6 V | exceed this and the pin is damaged |
The footnote that matters
That 40 mA is not a per-pin allowance you can spend freely. Espressif notes that per-pin sourced current is “gradually reduced from around 40 mA to around 29 mA” as more pins in the same power domain source current at once. Treat 40 mA as a ceiling you should never approach, not a budget.
Now the motor. The number that matters is not the running current — it is the stall current, the current the motor draws when the shaft is not turning.
A spinning motor generates a voltage opposing its supply, and that is what limits its current. At zero speed there is no such voltage, so the current is simply the supply divided by the winding resistance. Every motor passes through stall on the way to running — and returns to it any time something jams.
“It is not unusual for the stall current of a motor to be an order of magnitude higher than its free-run current.” — EDN, “Getting a handle on brushed DC motor current”.
| Variant | Free-run | Stall | Ratio |
|---|---|---|---|
| Low power (LP) | 50 mA | 360 mA | 7× |
| Medium power (MP) | 80 mA | 670 mA | 8× |
| High power (HP) | 120 mA | 1600 mA | 13× |
The smallest motor in that family asks for nine times what the pin can give. The largest asks for forty times. And a bare hobby motor with no gearbox is usually worse, not better.
Figures from Pololu's micro metal gearmotor specifications. Pololu publish honest stall figures; many cheap motors ship with no specification at all — which is what the bench exercise below is for.
Gate two — voltage
Can the pin reach it?
This one is quieter, and it is the reason your direct-drive motor might be running badly rather than not at all.
An ESP32 pin drives to 3.3 V. Your motor is rated 6 V. Even if current were free, a 3.3 V pin cannot make a 6 V motor do 6 V things — you get roughly half the speed and much less than half the torque. A motor that “works but seems weak” on a GPIO is not a mystery.
Where the motor's power comes from
The load current must never flow through the ESP32 or its dev board. Route the motor from your 6 V supply directly to the transistor, and connect only the grounds together. Pulling an amp through a dev board's regulator or its USB connector browns out the 3.3 V rail, and the ESP32 resets mid-motion — a fault that looks like a software bug and isn't.
Gate three — transient
Can the pin survive turn-off?
This is Lesson 01's gate. A motor winding is a coil, so everything from the flywheel lesson applies: when the switch opens, the current keeps flowing and the voltage climbs until something conducts.
Look again at the last row of the ESP32 table. The absolute maximum voltage on a pin is 3.6 V. Not 36. Not 360. The turn-off transient blows through that before the motor has noticed anything happened.
Your direct-drive circuit, specifically
With the motor wired straight to a pin, the pin is the switch that opens — so the coil's full transient lands directly on the silicon, which has no rating for it. And a flyback diode does not rescue this circuit. It fixes gate three and leaves gates one and two exactly as broken as they were.
The check
Run your own numbers
Three gates, three independent verdicts. Pick a load, or type your own numbers in, and watch which gates fail and what each one demands.
Notice what happens when you tick flyback diode fitted on a motor: exactly one gate flips. That is the whole answer to “why one over the other” — they were never alternatives.
Now try the LED preset. All three gates pass, and that is the honest answer to “or never one?”: direct drive is fine when it passes all three. A resistor-limited LED, a logic input, a piezo beeper. The rule is not “never hang things off pins” — it is “check first, every time.”
What the transistor actually is
A valve, not a shield
It is tempting to think of the transistor as protecting the pin. It doesn't. It replaces the pin as the thing carrying the current.
The mental model that holds up: the pin is a finger on a valve. The finger takes almost no effort — a few milliamps into a MOSFET gate, or a few hundred microamps into a BJT base. The water comes from the 6 V supply and goes through the valve, not through the finger. And the flyback diode sits across the load, where it always did, protecting whatever is doing the switching.
separate supply → provides the volts the pin cannot
flyback diode → absorbs the transient neither can
Which transistor, and how to drive its gate from only 3.3 V, is Lesson 03 — and there is a real trap waiting there. Many MOSFETs sold as “logic level” specify their on-resistance at a gate voltage of 4.5 V or 5 V, not 3.3 V. Driven from an ESP32 they never turn fully on, run hot, and fail slowly. Before then, put your existing transistor's part number somewhere you can find it.
Retrieval
Check yourself
On the bench
Measure your own motor's stall current
Your motor probably came without a datasheet. You can get the number yourself with the multimeter you already own — no scope, no bench supply, motor not even powered.
- Disconnect the motor from everything.
- Set the DMM to its lowest resistance range and measure across the two motor terminals.
- Turn the shaft a little and measure again. Repeat five or six times. The brushes contact different commutator segments at different positions, so the reading moves around — this is normal, not a bad meter.
- Take the lowest reading you saw. That is the worst case, and worst case is what you design for.
- Stall current = supply voltage ÷ that resistance. For 6 V into 4 Ω, that is 1.5 A.
- Put that number into the calculator above as worst-case mA, and read the verdict on your two circuits.
Two honest caveats. A cheap DMM's own lead resistance can be a large share of a few-ohm reading — short the probes together first and subtract what you see. And this method ignores winding inductance, so it gives you the steady stall current, not the switching transient. That is the right number for gate one.
Tell me what you measure and I will work through the part selection with you against your real number rather than a catalogue one.
Go deeper
Primary source
EDN — “Getting a handle on brushed DC motor current”.
Short, and it does one thing well: explains why motor current is a moving target and which number to design against. Read it before you buy a transistor. Pair it with the ESP32 datasheet — not to read through, but to practise finding Table 5-3 and reading a drive-strength spec straight from the source rather than from a tutorial.