# How to calculate base resistor of a NPN transistor that drives a MOSFET?

I'm currently trying to design a circuit that allows me to control a water pump running on 12V through an ESP32 microcontroller. The GPIO pins deliver only 3.3V, so I ended up controlling a NPN transistor (e.g. 2N2222) with the microcontroller and the transitor is connected to the MOSFET. Below is a schematic of what my circuit looks like:

D7 is connected to the microcontroller. My question is: How do I know what value of resistor I should use for R2? Usually that isn't such a big problem to figure out, but since I'm using a MOSFET I'm not quite sure how to do it.

• Your schematics is capsized, find some guidelines on how to draw a schematics. And it is wrong to me. Aug 11, 2020 at 13:20
• Explain why you need Q1. You claim that the transistor is needed because The GPIO pins deliver only 3.3V but in fact this transistor will lower the voltage at Q2's gate even further since you use Q1 as a common collector (or emitter follower). You reduces the 3.3 V to around 2.7 V!!! Aug 11, 2020 at 13:28

The circuit won't work regardless of the value of R2. The MOSFET will remain partially on all the time (due to R1), and possibly burn up. Even if R1 was to ground, the emitter-follower would only give you 2.6V from a 3.3V output regardless of whether the supply is 5V or 12V.

You could do something like this (logic is inverted):

simulate this circuit – Schematic created using CircuitLab

• Thank you! My bad for messing that up. May I ask why you ended up using a 10k Ohm resistor as the base resistor? Aug 11, 2020 at 13:31
• The DC current through R1 is about 1mA, so the base current should be at least 1/10 to 1/20 of that or 50-100uA. Voltage across R2 (when on) is (3.3V-0.7V)/R2 so R2 < 52K to 26K. 10K won't load the MCU much and will help the MOSFET switch off faster. You could use 4.7K and keep them both the same. We only need to worry about the precise calculation when the transistor (BJT) is switching a lot of current and we want to minimize the base current. Aug 11, 2020 at 13:37
• Now I get it. Thank you very much! Aug 11, 2020 at 13:41
• As usual a great answer. BUT, the OP should perhaps be warned that if the 5V and 12V supplies are energized before the processor, then the pump will be energized, even though the processor is not running. In other words, the default state of the pump is ON unless the processor is active and turns it OFF. If 5V and 12V are energized after the processor boots up then nothing to worry about. Also, briefly energizing the pump may not be a problem anyway, depending on the application. Aug 11, 2020 at 16:05
• @mkeith Yes, good point. If that's a problem, another BJT + resistor will solve it. (see edit). Aug 11, 2020 at 16:07

simulate this circuit – Schematic created using CircuitLab

Perhaps you were thinking somethin like this. The MCU, when outputs a high state, turns ON the MOSFET. While at low state or disconnected the R2 pulls-down the gate, to prevent spurious turn ON.

You probably meant this one, but it is not gonna work, since you have an emitter follower, so the gate voltage won't be higher that 3.3V.

simulate this circuit

• Yes, I accidentally swapped +/- in the schematic on that part. Thanks! Aug 11, 2020 at 13:41