Hi There
I have a N-Channel MOSFET that controls a relay.
Simply put : how can I protect my ESP32 pin from over-voltage if the polarity of the battery is switched?
In this second schematic the power is reversed, the diode prevents current flow through the MOSFET.
However the voltage on the GATE1 Pin will now be 28V.
This pin is directly connected to my ESP32 and I fear this will destroy the ESP32.
Well of course you can't apply 28V to the GPIO pin. But the second circuit doesn't work. Even if you used a P-channel mosfet as you should for high side switching, high side switching will always present the GPIO problem if the voltage being switched is higher than the Vcc of the processor. If you want high-side switching, you would need to use an NPN transistor or an N-channel mosfet to drive the gate of the main P-channel mosfet.
I'm trying to make sense of what you are saying, putting a diode where you suggested would result in no current flowing, the voltage however will still pass through the diode.
This is a case of reverse polarity, so that obviously means that there is no ground to pull the voltage down, thus meaning that the voltage will still remain 28V on the pin connected to the ESP32
If you like I can simulate it for you and you can have a look for yourself
I am using the first circuit, the second circuit is just showing how things would look if the polarity was switched, say for example by connecting the power source incorrectly.
Please read
In the above simulation, the battery is connected correctly. As you can see the wire in the plot view is the GATE1 NET. At normal operation this voltage is 0V when I am not applying a signal with the ESP32.
The 100k resistor basically just pulls the gate down to 0V if no signal is applied, to eliminate any stray signals or floating voltages that might trigger the MOSFET to turn on unwantedly.