understanding p-channel MOSFET unexpected behavior
You are disconnecting the gate of a mosfet by not pressing a button - this (due to high input impedance of the mosfet) leads to picking up charges from air (it acts like capacitor - try touching gate and ground/power), and partially turning mosfet on. To overcome this issue - add a high value resistor from Gate to ground - this will keep the mosfet on all the time, and when button is pressed - it will &quot;overwrite&quot; the resistor and turn transistor off as before. Value of added resistor should be in such range, that when button is pressed it will not drop the gate voltage to less than mosfet threshold voltage (or any voltage that is required for exact application)



simulate this circuit &ndash; Schematic created using CircuitLab