Arduino auto power-off - Page 1
Forum section: electronics / beginners

author: ema
author_rank: Newbie
timestamp: October 25, 2016, 12:42:14 am
content: Hi guys,I'm trying to create a simple circuit to auto shutdown Arduino after a certain amount of time.The schematic is attached to this message, but in a nutshell I'm using a pushbutton to ground the Arduino and therefore power it up; in parallel with the pushbutton there is a MOSFET with the gate connected to Arduino Pin 7. As soon as Arduino starts, Pin 7 goes high so is grounded through the MOSFET. After a certain amount of time Pin 7 goes low and the system turns off.I've tried different combination of resistors (a "big" gate-source and a smaller Pin7-gate), but the issue is that Arduino is drawing some current (~3mA with the configuration in the attached schematic) even when is off. I can see the ON led is lit although there isn't enough current to boot.Seems like the gate is drawing some current and therefore slightly opening the drain-source junction.If I increase the resistor between Pin7 and gate, Arduino stops drawing any current, but then the system goes off when I release the pushbutton (I guess the pull-down resistor "wins").The MOSFET I'm using ishttp://www.chinaeds.com/zl/20099221893384035_2SK3446pdf.pdfAny suggestion is much appreciated.CheersEdit:The schematic was wrong, I've updated it.

author: Brumby
author_rank: Unknown
timestamp: October 25, 2016, 12:53:37 am
content: Quote from: ema on October 25, 2016, 12:42:14 amThe schematic still looks wrong. The ground path from the Arduino can't work as you want.

author: rs20
author_rank: Super Contributor
timestamp: October 25, 2016, 01:03:11 am
content: Think about what will happen if the MOSFET turns off properly: the switch will be off, no current will flow out of the GND pin of the microcontroller, and hencethe GND pin will rise to 5V.But to keep the MOSFET off, its gate need to be held at 0V. This is a problem, because:1. With Pin D7 at 0V and chip gnd at 5V, you effectively have -5V on pin D7 which exceeds the absolute maximum ratings of the chip, and2. There are parisitic diodes in almost every IC running from GND up to every other pin, and from every other pin up to VCC. In particular, there is a diode running from ground to pin D7.Hence you have 5V, then the circuitry of the IC from VCC to GND (which will always have some leakage), then a parasitic diode from GND to D7, which goes straight into the gate of the MOSFET. Therefore, it is essentially impossible to turn the MOSFET off properly.There's nothing wrong with trying to interrupt the power on the ground side, except it's a lot more confusing for most of us who are familiar with ground-referenced systems. I'd recommend high-side switching to make it easier to think about.

author: ema
author_rank: Newbie
timestamp: October 25, 2016, 01:19:45 am
content: Thanks rs20, that was very clear.So what about if I move the logic from GND to Vin? I've attached another schematic. Would it work?

author: Mr.B
author_rank: Unknown
timestamp: October 25, 2016, 01:27:41 am
content: No, that will not work with N channel.You will not be able to pull the gate ~1.5v above the source to turn the FET on.

author: Mr.B
author_rank: Unknown
timestamp: October 25, 2016, 01:39:00 am
content: If you want to avoid the slow "boot" time of the Arduino and can afford a few micro-amps of power being consumed...Connect the Arduino permanently to the power supply.Connect a 100K resistor from pin 2 to +ve.Connect your push button between pin 2 and ground.Write code to put the Arduino into deep sleep and wake it up with an interrupt on pin 2.Total current draw excluding any peripherals you connect will be less than about 40 micro-amps. (Double check the datasheet for AtMega328p-AU to be sure)Code:// SLEEP BROWNOUT DISABLE FOR AtMega328p#define sleep_bod_disable() {uint8_t tempreg; __asm__ __volatile__("in %, %" "\n\t" "ori %, %" "\n\t" "out %, %" "\n\t" "andi %, %" "\n\t" "out %, %" :  "=&d" (tempreg) :  "I" _SFR_IO_ADDR(MCUCR),  "i" (_BV(BODS) | _BV(BODSE)),  "i" (~_BV(BODSE)));}/*****************************************************************************SOMEWHERE IN YOUR CODE - This is where you want the MCU to go to sleep.*****************************************************************************///Set up the interrupt on Arduino pin 2attachInterrupt(0, SLEEP_ISR, LOW);//Now put the device into deep sleep modecli(); // Turn off the global interuptsleep_enable(); // Set sleep enable bitsleep_bod_disable(); // Disable brown out detection during sleep. Saves more powersei(); // Turn on the global interuptpower_all_disable(); //This shuts down ADC, TWI, SPI, Timers and USARTsleep_cpu(); // Sleep the CPU as per the mode set earlier(power down)/////////////////////////////////////////////////////////////////////////////////////////// WHEN THE DEVICE WAKES UP - THIS IS THE ENTRY POINT/////////////////////////////////////////////////////////////////////////////////////////sleep_disable(); // Wakes up and clears the sleep enable bit. Before this ISR would have executedpower_all_enable(); // This enables ADC, TWI, SPI, Timers and USARTdelay(10); // This delay is required to allow CPU to stabilize// CARRY ON IN YOUR CODE/*****************************************************************************The interrupt service routine for the sleep function*****************************************************************************/void SLEEP_ISR(){detachInterrupt(0);}

author: rs20
author_rank: Super Contributor
timestamp: October 25, 2016, 03:32:35 am
content: If you still want a hardware switching option, you'd probably best off using a P-type FET -- Source to +5V, Drain to MCU VCC. If gate is at 5V, the FET is off, if gate is at 0V FET is on.This circuit is basically the same as the one you first posted, except totally flipped upside down. As it stands, it suffers from the same problem. When the switch is off, the VCC of the chip is at 0V, but the gate of the FET needs to be held at 5V. A parasitic diode running from MCU P7 to VCC will prevent this from working.We can solve this by using a second, N-type FET: Source to Gnd, Drain to the Gate of the first (P-type) FET, and Gate to MCU. Throw in one or two resistors which I'll leave as an exercise to you, and you have a workable solution -- although you have to decide whether having 2 discrete transistors offers enough of a power saving improvement to be better than Mr. B's solution, which is often a preferred approach.

author: ema
author_rank: Newbie
timestamp: October 26, 2016, 12:12:55 am
content: Thanks guys. I'll definitely look into the deep sleep mode which sounds promising. Now I'm using the UNO R3, but the final project will be built around a Pro Micro running at 8MHz. Hopefully will draw even less than 40uA.Cheers

author: Mr.B
author_rank: Unknown
timestamp: October 26, 2016, 12:33:44 am
content: Quote from: ema on October 26, 2016, 12:12:55 amWith all due respect, what are you trying to achieve?40uA is chicken shit.Take a small LiPo battery, say 250mAh.That can deliver a theoretical 250mA for one hour.Now lets draw 40uA, or 0.04mA250 / 0.04 = 6250 hours.6250 / 24 = ~260 days...Just checked the data sheet for the 328p.Power-save Supply Current appears to be <1uA @ 25C.This, of course is just the MCU.If you are running your device off a LiPo then the LDO Regulator will be burning some, along with whatever uncontrolled peripherals are connected.

author: ema
author_rank: Newbie
timestamp: October 26, 2016, 01:00:56 am
content: It's my first project and I'm trying to make a light meter (like the ones used in photography). The parts I ordered are:Leonardo Pro Micro ATmega32U4 8MHz 3.3V Replace ATmega328 Pro Mini ArduinoTSL2561 Luminosity Sensor Breakout infrared Light Sensor integrating sensor AL3-5V 0.96" SPI Serial 128X64 OLED LCD LED Display Module blue yellow for Arduino5PCS 5V Micro USB 1A 18650 Lithium Battery Charging Board Charger Moduletrying to power everything off a Li-Ion battery I scavenged from and old laptop.I reckon 40uA is good enough. Was just saying that the ATmega32U4 could draw even less, which is good

author: rs20
author_rank: Super Contributor
timestamp: October 26, 2016, 01:20:42 am
content: Quote from: Mr.B on October 26, 2016, 12:33:44 amNo need to be so aggressive, some people might enjoy pushing for 10uA or less, purely as a design challenge, even if the self-discharge of the battery dominates. Also, a photographic light meter that has a standby of 5 years instead of 1 year, is potentially a very useful thing indeed; even if one has to think very carefully about battery selection.

author: Mr.B
author_rank: Unknown
timestamp: October 26, 2016, 01:41:32 am
content: Quote from: ema on October 26, 2016, 01:00:56 amGood on you. Everyone has to start somewhere.QuoteYes, the ATmega32U4 will draw a lot less when in deep sleep.However...Looking at the circuit diagram for the Sparkfun version of the Pro Micro:It uses a MIC5219 as its LDO regulator - when supplying 100uA, it itself consumes 80uA.There is an on-board power LED which will need to be removed as it will consume about 1mA.Hopefully your OLED module has the ability to go into low power sleep as well.Cheers and good luck.

author: Mr.B
author_rank: Unknown
timestamp: October 26, 2016, 01:43:12 am
content: Quote from: rs20 on October 26, 2016, 01:20:42 amApologies.It was not my intention to come across that aggressive.

author: grifftech
author_rank: Frequent Contributor
timestamp: October 26, 2016, 02:53:23 pm
content: use a servo motor to flip a switch between the battery and your stuff.

author: rs20
author_rank: Super Contributor
timestamp: October 26, 2016, 11:17:05 pm
content: Quote from: grifftech on October 26, 2016, 02:53:23 pmThe more sensible version of that idea is the bistable relay.