ESP32 powering a solenoid

ESP_Sprite
Posts: 8921
Joined: Thu Nov 26, 2015 4:08 am

Re: ESP32 powering a solenoid

Postby ESP_Sprite » Sat Jun 06, 2020 8:54 am

Hm, seems the datasheet I was looking at was the 2n2222A instead of the non-A version, could be we got different results because of that.

bobtidey
Posts: 43
Joined: Mon Jun 18, 2018 2:24 pm

Re: ESP32 powering a solenoid

Postby bobtidey » Sat Jun 06, 2020 11:44 am

I think that even for the 2n2222A version it is hard to come up with a worst case design that provides sufficient Ib to saturate and yet doesn't potentially try to draw more than 40mA from a GPIO.

2n2222A max Vbe Sat @ 500mA Ic 2V might be a bit less at 300mA but not actually specified

Assume GPIO Vo under load 2.6V minimum then that would require Rb = 0.6 / .03 = 20 Ohm

Now if GPIO Vo - Vbe Sat under typical conditions only has to be > 0.8V to exceed 40mA

macdaddymays
Posts: 2
Joined: Tue Jun 09, 2020 5:49 pm

Re: ESP32 powering a solenoid

Postby macdaddymays » Wed Jun 10, 2020 9:26 pm

The 1k resistor mentioned at some point to go between the GPIO output of your ESP and the base of the 2N2222 should be used between the GPIO output of your ESP and the gate of the MOSFET. This will limit the inrush current attempting to flow out the GPIO output into the gate of your MOSFET to establish a gate-source charge. The gate pin of a MOSFET (N-channel or P-channel) should always be thought of as a capacitor and you should not connect a capacitor directly to a GPIO output. Finally, I would recommend a resistor between the gate and source pins of your MOSFET. If you are using 1k between your ESP GPIO output and the gate of your MOSFET, I would recommend something like 100k between the gate and source of your MOSFET. This will prevent the MOSFET from turning on the solenoid without an active control signal from your ESP GPIO output.

I am of the opinion that the GND connection of a DC-DC converter should not be connected to a MOSFET or a BJT. It will work, but the DC-DC converter needs a dedicated connection to the negative terminal of your batter. The solenoid, on the other hand, will work nicely if it is connected to GND through a MOSFET or a BJT. Oh, and ditto on the diode.

By the way, do you mind sharing what kind of MOSFET you ordered? Model #?

The relay should work, but you would almost certainly need to power/control the relay via the MOSFET AND you would need to treat the coil of the relay with a diode just like you will have to treat the solenoid with a diode.

Who is online

Users browsing this forum: No registered users and 56 guests