0
\$\begingroup\$

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:

enter image description here

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.

\$\endgroup\$
2
  • 2
    \$\begingroup\$ Your schematics is capsized, find some guidelines on how to draw a schematics. And it is wrong to me. \$\endgroup\$ Aug 11, 2020 at 13:20
  • 1
    \$\begingroup\$ 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!!! \$\endgroup\$ Aug 11, 2020 at 13:28

2 Answers 2

2
\$\begingroup\$

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):

schematic

simulate this circuit – Schematic created using CircuitLab

\$\endgroup\$
5
  • \$\begingroup\$ Thank you! My bad for messing that up. May I ask why you ended up using a 10k Ohm resistor as the base resistor? \$\endgroup\$
    – Gereon99
    Aug 11, 2020 at 13:31
  • 1
    \$\begingroup\$ 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. \$\endgroup\$ Aug 11, 2020 at 13:37
  • 1
    \$\begingroup\$ Now I get it. Thank you very much! \$\endgroup\$
    – Gereon99
    Aug 11, 2020 at 13:41
  • \$\begingroup\$ 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. \$\endgroup\$
    – mkeith
    Aug 11, 2020 at 16:05
  • 1
    \$\begingroup\$ @mkeith Yes, good point. If that's a problem, another BJT + resistor will solve it. (see edit). \$\endgroup\$ Aug 11, 2020 at 16:07
1
\$\begingroup\$

schematic

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.

schematic

simulate this circuit

\$\endgroup\$
1
  • \$\begingroup\$ Yes, I accidentally swapped +/- in the schematic on that part. Thanks! \$\endgroup\$
    – Gereon99
    Aug 11, 2020 at 13:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.