2
\$\begingroup\$

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

Schematic

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.

\$\endgroup\$
3
  • 1
    \$\begingroup\$ I suppose you mean 2N2222. and why using 5V when you have 12V supply already ? \$\endgroup\$ Aug 29, 2020 at 11:01
  • \$\begingroup\$ 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 \$\endgroup\$ Aug 29, 2020 at 14:42
  • \$\begingroup\$ What about just putting the instruction that drives the GPIO HIGH at the very beginning of your program? I imagine that would be so fast that we wouldn't see the LED actually turning on, right? How many milliseconds does it take to "boot" your system? \$\endgroup\$
    – LRMAAX
    Dec 5, 2023 at 16:03

2 Answers 2

4
\$\begingroup\$

You can add another transistor as an inverter.

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

schematic

simulate this circuit – Schematic created using CircuitLab

\$\endgroup\$
7
  • \$\begingroup\$ Thanks for your reply. So this is the best way to control 12v from 3.3v logic using IRFZ44N, right? \$\endgroup\$
    – Rishabh
    Aug 29, 2020 at 12:47
  • 1
    \$\begingroup\$ It should do what you want with the LED strip. "Best" is a pretty extreme claim. \$\endgroup\$ Aug 29, 2020 at 12:48
  • \$\begingroup\$ 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. \$\endgroup\$
    – Rishabh
    Aug 29, 2020 at 13:19
  • \$\begingroup\$ @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. \$\endgroup\$ Aug 29, 2020 at 13:26
  • 1
    \$\begingroup\$ Sure I'll replace that, thanks. \$\endgroup\$
    – Rishabh
    Sep 2, 2020 at 13:48
0
\$\begingroup\$

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:

enter image description here

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.

\$\endgroup\$
3
  • \$\begingroup\$ 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 \$\endgroup\$
    – Ilya
    Aug 29, 2020 at 11:54
  • \$\begingroup\$ 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? \$\endgroup\$
    – Rishabh
    Aug 29, 2020 at 12:39
  • \$\begingroup\$ 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 :) \$\endgroup\$
    – Ilya
    Aug 31, 2020 at 8:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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