# Simple ESP32 driver for solenoid valve rated 24V/2A?

( As an extension to the question asked here ESP32 driving Solenoid requiring 2A/24V DC with IRF520? , I am adding this question with the idea to help more peoples with the results, since seems like it's widely interesting question with variety of wrong answers on the google )

So - I have ESP32, which must drive solenoid valve rated on 24V/2A ( 1" 1/4' (Ф32) pipe valve ). The issues is that it turned on that the most showing on google transistor - IRF520 can NOT drive it directly, and there is a need of complex circuit, which is some cases is not suitable for beginners or peoples which does not complicate their circuits too much. The whole idea is the driver to work in ON/OFF mode (not PWM).

• What could be a reliable, simple and widely accessible components circuit which could drive such solenoid valves?
• With a bit of research google is pointing toward IRL520. but can't find proven circuit for it. – Yordan Yanakiev May 6 at 18:07

It's easy enough with a logic-level MOSFET, but unfortunately most good logic-level MOSFETs are in hobbyist-unfriendly SMT packages.

If an SO-8 is okay (easy to solder on breakout boards) then something like the IRF7470 will do the job.

simulate this circuit – Schematic created using CircuitLab

It has an Rds(on) of less than 30m$$\\Omega\$$ with only 2.8V drive, so power dissipation will be less than 120mW (very low, barely warm).

• o! Such a lot power transistor ?! Never thought about that way. I was going to set IRL540N just in case.. – Yordan Yanakiev May 7 at 21:48

Esp32 driving a Relay through NPN transitor seems good to me, I have an Incubator with Esp32 switching 60Watt Incandescent light bulb on Main 220v AC and a 100Watt Halogen Light Bulb on 12v DC Battery when Main is not available through (Different) Relays and it is working fine after months of use,

A simple Diagram should look like this:

If you decide to use a mosfet, try a logic level N-Channel mosfet with a big heat sink, you may also have to attach a soft starter to your solenoid valve otherwise your Mosfet could unexpectedly burn.

In either case, remember to put flyback diodes on Relay and/or Valve coils (A diode attached in opposite direction to supply voltage), Also don't forget Resistor from digital output of Esp32 to the base of Transistor, anything in the range of 100 Ohm to 1K should work.

• The OP wants to sink 2A for a solenoid. Your 1kohm base resistor is only going to provide about 2mA to the base, so the transistor will need $h_{FE} > 1000$ which is pretty high for a power transistor, – Elliot Alderson May 7 at 18:10
• Transistor is driving relay coil not solonoid, 12v relay coils typically sink around 30 mA and a resistor in the range i suggested should have no problem turning relay on @Elliot – asim May 7 at 19:11
• Ah, OK, it wasn't clear if you were saying that the OP should add a relay or if you were just giving an example of how a transistor could be used. – Elliot Alderson May 7 at 19:26
• "and/or" suggest that if mosfet is used, a flyback diode will be required at the solenoid coil but is not strictly required if relay is used instead depending on the power supply of OP but it would made the answer too long @Elliot – asim May 7 at 19:34
• You done actually my initial idea, before i go for MOSFET transistor as a driver. But You actually point me to something which I have never released and now I am worrying about - the internal structure of the solenoid valves. I really now wondering if the ones which i ordered will not causing decreasing of the overall flow or pressure.. – Yordan Yanakiev May 7 at 21:22