Aziz Bench

Transistor and MOSFET switch calculator

Will this transistor switch my load from a 3.3 V or 5 V pin? Pick the board, the part and the load: you get the base resistor or the gate verdict from the figures the datasheet guarantees, the heat, the flyback diode, and better options when it doesn’t work.

Verdict
Works
RDS(on) at most 48 mΩ with 3.3 V on the gate, 0.21 W of heat
Heat
0.21 W
Junction
52 °C
Gate voltage
3.3 V
The circuit
+12 VLOADGDSAO3400AGPIO3.3 V100 Ω10 kΩ

Better options

The usual ways to switch the same load, in the order that suits your values.

Now, AO3400A: 0.21 W of heat, junction 52 °C.

Less heat

Logic-level MOSFET

A MOSFET with RDS(on) guaranteed at 2.5 V or 4.5 V switches fully from a 3.3 V or 5 V pin, with little heat.

IRLML6344: 0.16 W of heat, junction 41 °C.

Fast PWM

MOSFET gate driver

A driver such as the TC4427 (1.5 A, 4.5–18 V supply, input high from 2.4 V) puts 10–12 V on the gate and switches in nanoseconds: for standard MOSFETs and fast PWM.

TC4427 from a separate 9 V supply (a regulator or a Zener) with the AO3400A: 0.14 W, junction 42 °C.

Diodes inside

ULN2003A or ULN2803A

7 or 8 Darlington channels with the flyback diodes inside, 50 V and 500 mA per channel: for relays, small solenoids and stepper motors. Each channel drops 1–1.6 V.

Over the 300 mA per channel it handles from this pin.

MOSFET module

Check which MOSFET the module carries. The common IRF520 module needs about 10 V on the gate; modules with a logic-level MOSFET or a gate driver work from 3.3 V.

Isolated

Relay module

Isolates the load completely and switches AC or DC with almost no heat. No PWM, slow, and the coil needs its own current: check that the module’s input works from 3.3 V.

AC loads

Solid-state relay

For mains AC loads: silent, no contacts to wear. AC models don’t switch DC: there are DC models for that.

Protected

Smart high-side switch

Chips such as Infineon’s PROFET switch the positive side with an N-MOSFET and a built-in charge pump, with current limiting and overtemperature protection.

Microcontroller pin
V
mA

An ESP32 pin sources up to 40 mA at its strongest drive setting; the default setting is the 20 mA step, used here.

Transistor

SOT-23 · up to 30 V and 5.7 A · RDS(on) 48 mΩ guaranteed from 2.5 V · threshold up to 1.45 V

Load
V
A

For a motor enter the stall current: it draws that much when starting or blocked.

Switch position

Low side: transistor between the load and ground. High side: between the positive supply and the load, with a P-channel MOSFET.

Hz

Leave 0 if you only switch on and off.

°C

Results

Load12 V × 2 A = 24 W (resistive load)
Gate100 Ω in series, 10 kΩ from gate to ground
RDS(on)at most 48 mΩ, guaranteed at 2.5 V (3 A); the gate gets 3.3 V, threshold up to 1.45 V
Voltage drop0.11 V (RDS(on) 54 mΩ when warm): 0.21 W
Junction temperature52 °C = 25 °C + 0.21 W × 125 °C/W
Ratings12 V of 30 V · 2 A of 5.7 A
In free airup to 1 W at 25 °C (θJA 125 °C/W)

Tips

Keep the 10 kΩ from gate to ground: while the microcontroller boots its pins float and the MOSFET could turn on by itself.

With amps flowing, keep the ground return of the load away from the microcontroller’s ground wire: join them at the power supply.

An SOT-23 sheds its heat through the copper on the drain pin: the datasheet figure assumes about 6.5 cm² (1 in²), a bare pad runs much hotter.

The microcontroller and the load supply must share ground, otherwise the gate or base has no reference.

Text ready to paste into a forum or an issue.

How the calculator decides

A transistor used as a switch should be fully off or fully on. Fully on means saturated for a bipolar transistor and at its low RDS(on) for a MOSFET: the drop across it is small, and so is the heat. The calculator checks that your pin can drive it there using only the figures the datasheet guarantees, then works out the heat and the junction temperature.

Bipolar transistors: base current and base resistor

The hFE in the datasheet is measured with several volts across the transistor, not in saturation. For the saturation voltage VCE(sat) the datasheets use a much lower gain, usually IC = 10 × IB (20 × for the BC547, 250 × for the TIP120 Darlington). The calculator uses that same forced gain, so the saturation voltage in the result is guaranteed.

IB = IC ÷ β(forced)
RB = (VGPIO − VBE(sat)) ÷ IB
P = VCE(sat) × IC + VBE(sat) × IB

Example: an ESP32 switching a 12 V relay coil of 70 mA with a 2N2222A. IB = 70 ÷ 10 = 7 mA and RB = (3.3 − 1.2) ÷ 0.007 = 300 Ω, rounded down to 270 Ω so the base gets a little more. The transistor drops at most 0.3 V: about 30 mW, nothing to worry about. At 300 mA the base would need 30 mA, more than the 20 mA an ESP32 pin should give: that is where a MOSFET takes over.

MOSFETs: the gate voltage that is actually guaranteed

The threshold voltage VGS(th) is not where a MOSFET turns on: it is where it barely starts to conduct, at 250 µA or 1 mA. What matters is the RDS(on) the datasheet guarantees at a given gate voltage. The AO3400A guarantees it at 2.5 V and switches fully from a 3.3 V pin. The IRLZ44N guarantees it from 4 V: fine from 5 V, not guaranteed from 3.3 V. The IRF520 and IRF540N guarantee it only at 10 V. Between the threshold and the lowest guaranteed point the datasheet promises nothing, and the calculator says so instead of guessing.

P = I² × RDS(on)(Tj) + Pswitching
Tj = Ta + P × θJA

RDS(on) rises with temperature, by about 1.5 times at 125 °C on these datasheets (1.43 for the AO3400A and 1.8 for the 2N7000, from their tables). The calculator raises it with the junction temperature and repeats until the two agree. Example: an AO3400A driven by an ESP32 switching a 2 A LED strip at 12 V. At 3.3 V the guaranteed figure is the 2.5 V one, 48 mΩ: 2² × 0.048 = 0.19 W, about 0.21 W once warm. At 125 °C/W the junction reaches about 52 °C.

Why the IRF520 module fails at 3.3 V

The common red IRF520 module connects the signal pin almost straight to the gate of an IRF520. Its threshold can be as high as 4 V and its RDS(on) is guaranteed only at 10 V. From a 3.3 V ESP32 it may not turn on at all; from a 5 V Arduino it conducts only partly and heats up with a few amps. From 5 V you can replace it with a logic-level MOSFET with the same pinout, such as the IRLZ44N or the IRLB8721. From 3.3 V use a MOSFET guaranteed at 2.5 V or a gate driver.

Motors, relays and solenoids: the flyback diode

A coil resists changes in current. When the transistor turns off, the coil keeps the current flowing and its voltage shoots up until something breaks down, usually the transistor. A diode across the load, cathode to the positive supply, gives that current a path. For relays switched on and off a 1N4148 (small coils) or a 1N4007 is enough; with PWM on a motor use a Schottky diode such as the 1N5819 (1 A) or the SS34 (3 A), rated for the load current.

High side: P-channel MOSFET and level shifter

Sometimes the load must keep its ground connection and the switch goes between the supply and the load. With a P-channel MOSFET the source goes to the positive supply and a resistor pulls the gate up to the same voltage (off); a small NPN driven by the pin pulls the gate down (on). The gate then sees the whole supply voltage: above 80 % of the MOSFET’s gate limit the calculator adds a divider. A pin can’t drive the P-MOSFET directly when the supply is higher than the pin voltage: the MOSFET would never turn off.

PWM and switching losses

At every edge the MOSFET spends a moment half on, with both voltage and current. A microcontroller pin moves the gate charge with a few tens of milliamps, so an IRLZ44N (48 nC) needs a few microseconds per edge: harmless at 1 kHz, a few watts at 20 kHz with 5 A. The calculator estimates it as ½ × V × I × (rise + fall time) × frequency, with the whole gate charge, which errs on the safe side. For fast PWM use a small MOSFET with a low gate charge or a gate driver.

The transistors in the list

PartTypePackageMax VMax IGuaranteedAt 3.3 VAt 5 VθJA
2N2222ANPNTO-9240 V600 mAVCE(sat) 1 V / 500 mA——200 °C/W
2N3904NPNTO-9240 V200 mAVCE(sat) 0.3 V / 50 mA——200 °C/W
BC547NPNTO-9245 V100 mAVCE(sat) 0.6 V / 100 mA——200 °C/W
S8050NPNSOT-2325 V500 mAVCE(sat) 0.6 V / 500 mA——417 °C/W
TIP120NPN DarlingtonTO-22060 V5 AVCE(sat) 4 V / 5 A——62.5 °C/W
2N7000N-channel MOSFETTO-9260 V200 mARDS(on) 5.3 Ω / 4.5 Vnot guaranteed5.3 Ω313 °C/W
BS170N-channel MOSFETTO-9260 V500 mARDS(on) 5 Ω / 10 Vnot guaranteednot guaranteed357 °C/W
AO3400AN-channel MOSFETSOT-2330 V5.7 ARDS(on) 48 mΩ / 2.5 V48 mΩ32 mΩ125 °C/W
Si2302N-channel MOSFETSOT-2320 V2.6 ARDS(on) 75 mΩ / 2.5 V75 mΩ57 mΩ175 °C/W
IRLML6344N-channel MOSFETSOT-2330 V5 ARDS(on) 37 mΩ / 2.5 V37 mΩ29 mΩ100 °C/W
IRLZ44NN-channel MOSFETTO-22055 V47 ARDS(on) 35 mΩ / 4 Vnot guaranteed25 mΩ62 °C/W
IRLB8721N-channel MOSFETTO-22030 V62 ARDS(on) 16 mΩ / 4.5 Vnot guaranteed16 mΩ62 °C/W
IRF520N-channel MOSFETTO-220100 V9.2 ARDS(on) 270 mΩ / 10 Vnot guaranteednot guaranteed62 °C/W
IRF540NN-channel MOSFETTO-220100 V33 ARDS(on) 44 mΩ / 10 Vnot guaranteednot guaranteed62 °C/W
AO3401AP-channel MOSFETSOT-2330 V4 ARDS(on) 85 mΩ / −2.5 V——125 °C/W
IRF9540NP-channel MOSFETTO-220100 V23 ARDS(on) 117 mΩ / −10 V——62 °C/W

Guaranteed maximum figures at 25 °C from the makers’ datasheets (onsemi, CJ, Alpha & Omega, Vishay, Infineon). At 3.3 V and at 5 V: the RDS(on) guaranteed with that gate voltage. θJA was measured on each maker’s test board, about 6.5 cm² of copper for the SOT-23 parts: with less copper they run hotter.

Frequently asked questions

Can an ESP32 drive a MOSFET directly?

Yes, if the MOSFET’s RDS(on) is guaranteed at 2.5 V or less, like the AO3400A, Si2302 or IRLML6344. Add 100 Ω in series with the gate and 10 kΩ from gate to ground, so it stays off while the ESP32 boots. The IRLZ44N, often sold as logic-level, is guaranteed only from 4 V.

Why doesn’t my IRF520 module work with 3.3 V?

Because the IRF520 is not a logic-level MOSFET: its threshold can be 4 V and its RDS(on) is guaranteed only at 10 V. From 3.3 V it may not turn on at all. Use a gate driver, a module with a logic-level MOSFET, or a MOSFET guaranteed at 2.5 V such as the AO3400A.

What base resistor does a transistor switch need?

RB = (VGPIO − VBE(sat)) ÷ IB, with IB = IC ÷ 10 for most small transistors (IC ÷ 20 for the BC547). For 100 mA from a 5 V Arduino with a 2N2222A: IB = 10 mA and RB = (5 − 1.2) ÷ 0.01 = 380 Ω, so 330 Ω.

TIP120 or MOSFET?

From a 5 V Arduino a TIP120 works with little base current, but it drops up to 2 V at 3 A: up to 6 W of heat. A logic-level MOSFET drops a few tens of millivolts at the same current. From an ESP32 choose a MOSFET guaranteed at 2.5 V.

Do I need a flyback diode?

Yes for anything with a coil: motors, relays, solenoids, valves, fans. Fit it across the load with the cathode (the end with the stripe) to the positive supply. LED strips and heaters don’t need one.

How much current can an SOT-23 MOSFET switch?

The rating says several amps, but the heat decides. An AO3400A driven from a 3.3 V pin dissipates about 0.2 W at 2 A and stays near 50 °C; at 3 A it gets close to 100 °C. More copper around the drain pin helps.

High side or low side?

The low side (transistor between the load and ground) is simpler: an N-channel MOSFET or an NPN driven straight from the pin. Use the high side when the load must keep its ground, for example a sensor that shares ground with the microcontroller: then a P-channel MOSFET with a small NPN that pulls its gate down.