I was working on a project that I wanted to run for 30 seconds and then permanently disconnect from power. The project was a battery powered kids toy. Kids will not remember to turn a power switch off after playing. So to conserve the battery I wanted to have a momentary switch that would turn on the toy and then after 30 seconds it would turn itself off.
I was able to find some similar circuits and adapt them to this application. The circuit uses 2x MOSFETs, a pushbutton, and a digital output on the Arduino.
How it works:
The momentary pushbutton temporarily connects the battery power to the Vin on the Arduino.
The Arduino boots up and turns on a digital output.
The digital output turns on the MOSFET which connects the battery power to the Vin on the Arduino.
The pushbutton can now be released and the Arduino will continue to have power.
When the Arduino reaches a line of code that turns the digital output off, the power to the Arduino is disconnected.
I will explain the operation below.
This circuit allows an Arduino to disconnect itself from power. The Drain, Gate, and Source on the MOSFETS are marked with "D","G", and "S".
IRF9530N P channel MOSFET
IRF510N N channel MOSFET
2x 10K Ohm resistors
Momentary pushbutton
9V battery
Arduino UNO
First I will give some details about the MOSFETS. I need to find out what conditions cause the MOSFET to be "ON" or "OFF". ON means there is very low resistance between Drain and Source (marked as D and S in the circuit above). In other words, ON is a closed switch. MOSFETS are turned ON or OFF based on the value of Vgs which is the voltage difference between the gate and the source pins.
In the schematic Q1 is an N channel MOSFET. To find out the behavior of this device we can look in the datasheet and see that the Vgs(th) is between 2.0 to 4.0 Volts. That means it is an enhancement mode MOSFET. Vgs(th) is the threshold where the MOSFET will begin to turn ON. Q2 is a P channel MOSFET. The datasheet shows that Vgs(th) is between -2.0 to -4.0 Volts which means it is also an enhancement mode MOSFET. The table below shows the behavior of these MOSFETS for different values of Vgs.
Using the table above I will go through the circuit operation by looking at the 3 states:
Default/Idle - pushbutton is not pressed, Arduino is off
Q1 - D4 on the Arduino is OFF. Q1_G is pulled to ground through R1. Q1_S is connected to ground. The result is Q1_Vgs = 0. Referring to the table above, Q1 is OFF.
Q2 - SInce Q1 is OFF and SW1 is open, there is no current flowing from the battery. That means there is no current through R2 and no voltage drop. So Q1_G and Q1_S are at the same voltage. This means Q2_Vgs=0 and Q2 is OFF.
Pushbutton is pressed
9 Volts from the battery is connected to Vin on the Arduino. The Arduino boots up.
Arduino is active (D4 is ON)/pushbutton is released
Q1 - D4 on the Arduino is ON which means it is outputting 5 Volts. Q1_G = 5 Volts. Q1_S is connected to ground. The result is Q1_Vgs = (5-0) = 5 Volts. Referring to the table above, Q1 is ON.
Q2 - SInce Q1 is ON , there is current flowing from the battery through R2 and through Q1. That means there is a voltage drop across R2. So the voltage at Q2_G is less than Q2_S which gives Q2_Vgs<0 and Q2 is ON. When Q2 is ON the 9V battery is connected to Vin on the Arduino. The Arduino will remain powered on while D4 is ON.