Power off arduino via software
A system I commonly use:







simulate this circuit &ndash; Schematic created using CircuitLab

M1 is normally held OFF by R1. SW1 pull M1 gate LOW when pressed switching M1 on. That then provides power to the Arduino.

The first operation the Arduino performs is to drive the GPIO connected to the gate of M2 (which must be a "logic level" FET with a threshold low enough to drive directly with an Arduino - you could also use an NPN BJT). That then bypasses switch SW1 keeping the system powered up.

The switch can then be released and the power stays on.

The Arduino can then release the GPIO by either driving it LOW or setting it to INPUT (R3 will pull it down in that case) switching off M2 which then allows R1 to pull up the gate of M1 switching it off.

The only down side to this circuit when working with an Arduino is you need to hold the power button in long enough for the bootloader to finish executing (about 2 seconds) before the power will stay on. It can be beneficial to add an LED (and associated current limiting resistor) to the GPIO that drives the gate of M2 so you get a visual feedback of "power on" (or you could use a separate GPIO if you so wished) so you know when you have held the button long enough.