Arduino locks up when used with P-channel MOSFET

Hi there,

I try to build my own Amazon dash button, since they took the service down permanently.
I'am using a P-channel logic level Mosfet (https://www.vishay.com/docs/72245/72245.pdf) which is connected to a 3.3 V power source at source and the gate is pulled with a 4.7k resistor also to 3.3 V. The drain is then connected to the arduino and a push button, which is also connected to 3.3 V with it's input.

In my sketch I set the pin to low which is connected to the gate, as soon as the arduino is booted up which results in 3.3 V at the drain and the arduino recieves it's power but locks up (so he literally freezes...) as soon as the FET is open and 3.3 V are flowing.

So at start the FET is closed, I push the button, the Arduino gets power, sets the gate low and hangs up...

I would love some help because I wasted like 3 hours tinkering around with resistors and caps, and can't figure out the problem... :frowning:

Thanks a lot!

Hello Majuss,
Welcome to the forum.

The first problem is that the data sheet you linked to shows a FET with a completely different package to the one on the diagram, so I have no way of knowing if you have even wired it up in sensible way. The diagram cannot possibly be correct for that FET.

Please can you:
Provide an accurate schematic, hand drawn and photographed is fine.
Provide photos of your actual work, these should be clear, in focus and allow us to see the wiring and trace it in the photo.
Provide your code, in code tags as per the forum instructions.

Thank you.

Majuss's diagram

gate, drain, source. Not source, drain, gate.

I can assure you that the wiring is not the problem, I checked it a million times and measured everything with a multimeter (ports of the fets, voltage behaviour of the gate and drain etc...). The fritzing schematic was just exemplaric, but if you really need an acurate one, I will create one tomorrow with kicad.

The speaker is just there to show if the ESP still lives. The blue LED blinks ones when the button is pressed, then it's locked and button pressing will do nothing since the gate is pulled to 0 V and the fet is open.

#include <Arduino.h>

void setup()
{
  pinMode(15, OUTPUT);
  pinMode(5, OUTPUT);
  digitalWrite(15, LOW);
}

void loop()
{
  tone(5, 100);
  delay(100);
  noTone(5);
  delay(1000);
}

I can assure you that the wiring is not the problem

Well, that's up to you. If you want help then you have to provide the information asked for. You don't, of course, have to provide any particular piece of information, and we, of course, don't have to help.

I believe the wiring IS the problem, if its as drawn....

So here is the 100% acurate schematic.

OP's schematic:


You're using GPIO15 as the output that drives the MOSFET, but this is one of the boot pins. The fact that it is being held HIGH on startup means that it is trying to boot off of an SD card.
Try using GPIO6-GPIO11 and see how you go.
For further information, see this page.

That circuit is flawed, the GPIO pin is held LOW when the chip is powered down by the protection diode, which turns on the MOSFET, powers up the chip, floats the GPIO pin and lets the MOSFET gate discharge through R2,
turning off the MOSFET, powers down the chip, the GPIO pin is clamped low by the protection diode, the MOSFET turns on, etc, etc.

No auto-switch circuit can be made from a single active device like this due to the protection diodes
phantom-powering the chip.

You need at least two active devices to implement such a switch, or a reed-relay.

Wow I'am staggered right now! Thank you for the help this was indeed the problem! I'am now using GPIO13, since 6-11 are not available on the WEMOS D1 mini.

Thank you so much @BJHenry and everyone else :slight_smile:

@MarkT after switching to GPIO13 it now works flawlessly.

Is that pin without protection diode(*)? Or have you burnt it out?

(*) 5V tolerant pins on a 3.3V chip cannot have a upper protection diode, for instance.

Espressif has removed all references to the ESP8266 being 5V tolerant from their documentation.

Hello Majuss,
That schematic is a million times better than the one in your original post.

If I had seen this earlier I would have completely missed the point that BJHenry made, I learned something there.

I might have said something similar to what Mark T said, that was my suspicion when you first asked about the problem.

Good luck with your project.