# Drive IRFZ44N Mosfet with 2N2222 NPN Transistor from ESP8266

I have made a circuit which controls 12v led from ESP8266. Led is being switched from IRFZ44N Mosfet. To convert logic from 3.3v to 5v, I used 2N2222 transistor. So my overall circuit looks like this:-

This circuit is working fine except on writing ESP pin HIGH, led turns off and on writing gpio LOW, led turns on. This is problematic because on resetting ESP, led stays on until code reaches the turning gpio HIGH. Please suggest me a solution for this. I know its a dumb question but I can no where find related question, that's why I asked a fresh one.

• I suppose you mean 2N2222. and why using 5V when you have 12V supply already ? – Tirdad Sadri Nejad Aug 29 '20 at 11:01
• Remember that a low side switch is an inverter and all collector/drains invert so you have 3 cascaded inverters leading to negative logic. thus using a NPN+ with Rpu, Rs to Pch high side FET you can have an even number so positive logic. Just counting even/odd inversions is the simple way to view logic – Tony Stewart EE75 Aug 29 '20 at 14:42

You can add another transistor as an inverter.

Also, for IRFZ44, as opposed to IRLZ44, you should have the pullup to +12.

simulate this circuit – Schematic created using CircuitLab

• Thanks for your reply. So this is the best way to control 12v from 3.3v logic using IRFZ44N, right? – Rishabh Aug 29 '20 at 12:47
• It should do what you want with the LED strip. "Best" is a pretty extreme claim. – Spehro Pefhany Aug 29 '20 at 12:48
• Sure. Thanks. Actually load I want to control is not led but solenoid based electronic lock which works with 12v 5Amps supply. Will this circuit work good for this lock too? And yes I'll be using flyback diode across solenoid. – Rishabh Aug 29 '20 at 13:19
• @Rishabh Yes, it should be fine for that, with the flyback diode, however I might be tempted to use a bit better MOSFET (lower Rds(on) with Vgs = 10V) than the 28m$\Omega$ of the IRFZ44. For example, the IRLB4132PbF is 3.5m$\Omega$ and costs no more, so it won't even get warm at 5A. – Spehro Pefhany Aug 29 '20 at 13:26
• Sure I'll replace that, thanks. – Rishabh Sep 2 '20 at 13:48

You can control higher voltage with low voltage signal using N-channel MOSFET. It's not exactly converting to 5V logic, it's driving 12V directly with 3.3V, which is your ultimate goal as far as I understand it.

Your solution inverts an input, so if you add another BJT you can invert your signal and get 5V logic. My solution is however simpler and more common for driving higher voltage with lower voltage:

IRF9530: P-channel mosfet (it was just default) IRF530: N-channel logic level mosfet (opens with low voltage like 2V, so 3.3V is well enough to drive it, it's also default, you'll need to find logic level one)

N-channel MOSFET CAN BE REPLACED with NPN BJT (don't forget base resistor) Mosfet solution is more energy efficient due to no gate current unlike bjt's base current.

GPIO goes HIGH, N-MOSFET or BJT opens, pulls P-channels gate to ground, P-Channel opens. If N-MOSFET or BJT is not conducting, P-Channels gate is at 12V and it's closed. Mission accomplished.

• If you drive directly from GPIO pinm you don't need R3. You may want to place a series resistor of 100-1000 ohm between SW1 and R3 in series, but it's not strictly necessary – Ilya Aug 29 '20 at 11:54
• Thanks for the solution. Yes my ultimate goal is to switch 12v with 3.3v logic. Actually I know about logic level mosfets such as IRLZ44N which can be driven directly from 3.3v but actually they costs me more and I have too many IRFZ44N lying around. I got the energy efficiency point of using N-Channel mosfet but the problem in my case is lack of physical space on circuit board, so I think I have to go with npn bjt. So to sum it up, you are suggesting me to replace IRFZ44N(N-Channel) with IRF9530(P-Channel) mosfet in my schematic, right? – Rishabh Aug 29 '20 at 12:39
• Yep, and P-Channel is a high side switch obviously. And throw in a BJT instead of MOSFET, everyone has generic BJTs in some box lying around, so it shouldn't be a problem :) – Ilya Aug 31 '20 at 8:01