// How to Make Auto Power OFF Circuit with Arduino?
// https://circuitjournal.com/arduino-auto-power-off#:~:text=To%20shut%20down%20the%20Arduino,Digital%20Output%20D7%20to%20LOW.
/*
How to Make Auto Power OFF Circuit with Arduino?
The charge of a battery is limited. It would be nice if your battery-powered device could power itself OFF if it has been idle for some time.
With a couple of MOSFETs and some resistors, you can create a circuit that makes it possible for your Arduino to use a Digital Output pin to shut itself OFF.
In this article, I am going to explain step-by-step how to make the connections. First, let's make the basic connections, and then optionally, we can add some wires
to read the push button status in your Arduino code.
*/
long shutdownTimer = 0;
void setup() {
pinMode(10, INPUT_PULLUP); // PCB Me Switch na lagaye But Code me rahne de
pinMode(7, OUTPUT); // hold the power mosfet ON // Ye +ve voltage N-Channel Mosfet k Gate par ja kar use On mode me layega
digitalWrite(7, HIGH); // Dhyan rahe Suru se hi Pin7 HIGH declare hai....yani Shutdown time = 180000; k baad hi LOW hoga
}
void loop() {
while (millis() - shutdownTimer < 30000) { // wait for the shut-down timer // 5000// iss timer se Power Mosfet iss time tak hold rahta hai...yani Pin7 HIGH rahti hai
// Aur agar Running yani Shutdown time = 180000; k bich me hi if the button is pressed (pin 10 is pulled to ground)then (extra Time add ho jayega )extend shutdownTimer and blink the on-board LED
if (!digitalRead(10)) {
shutdownTimer = millis();
}
}
digitalWrite(7, LOW); // when the time is up then shut it down
delay(1000); // give it time to shut down
}