(SOLVED)Switchable power using P Channel MOSFET circuit fails on external power.

I’m having major voltage drop/brownout issues with an esp32 devboard when I initialise the onboard WiFi. As a result I’m setting up a switchable 5V power bus for my peripheral devices using a P-channel MOSFET so I can power these up after the WiFi is connected.

The switch works perfectly when running from usb power, but when I power everything from an external 5V/3A power adapter plugged into the breadboard rail, the circuit fails and the LED in continually ON. If I remove the switch pin from the breadboard the LED switches off. Can someone please advise what would be causing this behaviour and how I might troubleshoot or rectify?

Bodgey Sketch below as well as photo of my very simple circuit. I can make a fritzing diagram if better, but it’s a very simple layout.

Many Thanks.

/*
    Testing barebone Network connectivity using LED as indicator.
    Switchable 5V supply controlled by MOSPIN

*/


#include "esp_wifi.h"
#include <WiFi.h>

// ===== Network credentials and Config =====
const char* localHostname = "nodeboxin" ;
const char* ssid     = "XXXXX" ;
const char* password = "XXXXXXXXX" ;

const int LEDPIN = 2;
const int MOSPIN = 4;

void setup() {
  Serial.begin(9600);
  delay(50);
  pinMode(MOSPIN, OUTPUT);
  digitalWrite(MOSPIN, HIGH);
  pinMode(LEDPIN, OUTPUT);

  // flash onboard LED 5 times to show stable running
  Serial.print("Running in setup");
  for ( int i = 0; i < 5; i++) {
    digitalWrite(LEDPIN, HIGH);
    delay(250);
    digitalWrite(LEDPIN, LOW);
    delay(200);
  }
  // initiate network
  esp_wifi_set_max_tx_power(20);            // Set WiFi TX power low
  WiFi.setHostname(localHostname) ;         // set hostname
  WiFi.begin(ssid, password) ;              // connect to WiFi
  while (WiFi.status() != WL_CONNECTED) {
    delay(500) ;
    Serial.print("not connected");
  }
  // if connected, flash led 3 times fast then 3 times slow
  if (WiFi.status() == WL_CONNECTED) {
    for (int i = 0 ; i < 3 ; i++) {
      digitalWrite(LEDPIN, HIGH);
      delay(200);
      digitalWrite(LEDPIN, LOW);
      delay(100);
    }

    for (int n = 0 ; n < 3 ; n++) {
      digitalWrite(LEDPIN, HIGH);
      delay(500);
      digitalWrite(LEDPIN, LOW);
      delay(200);
    }
  }
  Serial.print("End setup");
  Serial.print(WiFi.localIP()) ;
}


void loop() {
  Serial.println("In loop");
  Serial.println(WiFi.localIP()) ;

  delay(1000);
  for (int p = 0; p < 30; p++) {
    digitalWrite(LEDPIN, HIGH);
    delay(250);
    digitalWrite(LEDPIN, LOW);
    delay(100);
  }
  digitalWrite(MOSPIN, LOW);
  Serial.println("Turning on FET");
  delay(5000);
  digitalWrite(MOSPIN, HIGH);
  Serial.println("Fet off");
}

Show us a good schematic.

Hope this is sufficient.

The values of the resistors are 330 (gold) and 10K (blue) Ohms. The cap across the bottom rail is a 1mF electrolytic.

What is the part number written on the P channel MOSFET ?

Please measure the external 5v power supply voltage, what is it ?

Please measure the output pin voltage when it is HIGH, what is it ?

Please measure the 5v pin voltage on the controller, what is it ?

Thanks Larry.

The MOSFET number is FQP 47P06.

Your reply got me thinking about the fact I'm trying to pull up the gate using 3.3V but the pull-up was connected to 5V :confused: Also when I woke up this morning I thought maybe I should be using a low-side switch to control ground to the switchable circuit.

The modified low-side circuit shown below now works as expected.

Thanks.

Some sample ccts. you might be interested in:

Thanks for your guidance :slight_smile: