Auto Power off after certain time not working in micro

i tried to create the circuit from this 2 tutorila that ower on the ardinuo with pushbutton and shuts off after 5 second with Ardinuo micro and mega.

it works fine in mega.

but in pro it works first time when in push the button and ardinuo shuts off after 5 sec but second time i push the button it lights all the light in the board but does not hold the power for 5 sec. it works when in push the reset pin after ardinuo gets power.

any idea?

http://www.zolalab.com.br/eletronica_projetos/auto_shutdown_enus.php


// Pin definitions
#define OLED_RESET 4
const int MOSFETPIN = A1; 

void setup(void)
{

pinMode(MOSFETPIN, OUTPUT);

digitalWrite(MOSFETPIN, HIGH);

delay(5000);

digitalWrite(MOSFETPIN, LOW);

}

void loop() {

}

If the Micro uses 3.3V logic, the Mosfet might be totally turned on or off due to the gate not being driven completely open or closed at 3.3VDC.

it works after 5 sec holding the push button. i think the boot loader is doing something.

also find out that after ardinuo shuts off all the pins are getting high.

Leroy2007:
If the Micro uses 3.3V logic, the Mosfet might be totally turned on or off due to the gate not being driven completely open or closed at 3.3VDC.

it’s running on 5v.

// Pin definitions
#define OLED_RESET 4
const int MOSFETPIN =  A1; 

void setup(void)
{
  
  pinMode(MOSFETPIN, OUTPUT);
  pinMode(7, OUTPUT);

  digitalWrite(MOSFETPIN, HIGH);

 digitalWrite(7, HIGH);
  delay(10000);

  digitalWrite(MOSFETPIN, LOW);

}

void loop() {

}

this one turned the ardinuo off after 10 sec but led was not turned off.

is there a circuit that works and different from this 2 i have?

here it says i can't power the ardinuo with one mosfet.
https://circuitjournal.com/arduino-auto-power-off