Author Topic: Arduino auto power-off  (Read 8052 times)

0 Members and 1 Guest are viewing this topic.

Offline emaTopic starter

  • Newbie
  • Posts: 5
  • Country: au
Arduino auto power-off
« on: October 25, 2016, 12:42:14 am »
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 is http://www.chinaeds.com/zl/20099221893384035_2SK3446pdf.pdf

Any suggestion is much appreciated.

Cheers

Edit:
The schematic was wrong, I've updated it.

« Last Edit: October 25, 2016, 12:47:38 am by ema »
 

Offline Brumby

  • Supporter
  • ****
  • Posts: 12297
  • Country: au
Re: Arduino auto power-off
« Reply #1 on: October 25, 2016, 12:53:37 am »
Edit:
The schematic was wrong, I've updated it.

The schematic still looks wrong.  The ground path from the Arduino can't work as you want.
 

Offline rs20

  • Super Contributor
  • ***
  • Posts: 2318
  • Country: au
Re: Arduino auto power-off
« Reply #2 on: October 25, 2016, 01:03:11 am »
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 hence the 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, and
2. 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.
« Last Edit: October 25, 2016, 01:06:24 am by rs20 »
 

Offline emaTopic starter

  • Newbie
  • Posts: 5
  • Country: au
Re: Arduino auto power-off
« Reply #3 on: October 25, 2016, 01:19:45 am »
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?
 

Offline Mr.B

  • Supporter
  • ****
  • Posts: 1237
  • Country: nz
Re: Arduino auto power-off
« Reply #4 on: October 25, 2016, 01:27:41 am »
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.
I approach the thinking of all of my posts using AI in the first instance. (Awkward Irregularity)
 

Offline Mr.B

  • Supporter
  • ****
  • Posts: 1237
  • Country: nz
Re: Arduino auto power-off
« Reply #5 on: October 25, 2016, 01:39:00 am »
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: [Select]

// SLEEP BROWNOUT DISABLE FOR AtMega328p
#define sleep_bod_disable() {uint8_t tempreg;  __asm__ __volatile__("in %[tempreg], %[mcucr]" "\n\t" "ori %[tempreg], %[bods_bodse]" "\n\t" "out %[mcucr], %[tempreg]" "\n\t" "andi %[tempreg], %[not_bodse]" "\n\t" "out %[mcucr], %[tempreg]" : [tempreg] "=&d" (tempreg) : [mcucr] "I" _SFR_IO_ADDR(MCUCR), [bods_bodse] "i" (_BV(BODS) | _BV(BODSE)), [not_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 2
attachInterrupt(0, SLEEP_ISR, LOW);
//Now put the device into deep sleep mode
cli();               // Turn off the global interupt
sleep_enable();      // Set sleep enable bit
sleep_bod_disable(); // Disable brown out detection during sleep. Saves more power
sei();               // Turn on the global interupt
power_all_disable(); //This shuts down ADC, TWI, SPI, Timers and USART
sleep_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 executed
power_all_enable();    // This enables ADC, TWI, SPI, Timers and USART
delay(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);
}

I approach the thinking of all of my posts using AI in the first instance. (Awkward Irregularity)
 
The following users thanked this post: ema

Offline rs20

  • Super Contributor
  • ***
  • Posts: 2318
  • Country: au
Re: Arduino auto power-off
« Reply #6 on: October 25, 2016, 03:32:35 am »
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.
 

Offline emaTopic starter

  • Newbie
  • Posts: 5
  • Country: au
Re: Arduino auto power-off
« Reply #7 on: October 26, 2016, 12:12:55 am »
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
 

Offline Mr.B

  • Supporter
  • ****
  • Posts: 1237
  • Country: nz
Re: Arduino auto power-off
« Reply #8 on: October 26, 2016, 12:33:44 am »
Hopefully will draw even less than 40uA.

With 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.04mA
250 / 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.
I approach the thinking of all of my posts using AI in the first instance. (Awkward Irregularity)
 

Offline emaTopic starter

  • Newbie
  • Posts: 5
  • Country: au
Re: Arduino auto power-off
« Reply #9 on: October 26, 2016, 01:00:56 am »
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 Arduino
TSL2561 Luminosity Sensor Breakout infrared Light Sensor integrating sensor AL
3-5V 0.96" SPI Serial 128X64 OLED LCD LED Display Module blue yellow for Arduino
5PCS 5V Micro USB 1A 18650 Lithium Battery Charging Board Charger Module

trying 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 :)
 

Offline rs20

  • Super Contributor
  • ***
  • Posts: 2318
  • Country: au
Re: Arduino auto power-off
« Reply #10 on: October 26, 2016, 01:20:42 am »
With all due respect, what are you trying to achieve?
40uA is chicken shit.

No 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.
 

Offline Mr.B

  • Supporter
  • ****
  • Posts: 1237
  • Country: nz
Re: Arduino auto power-off
« Reply #11 on: October 26, 2016, 01:41:32 am »
It's my first project and I'm trying to make a light meter (like the ones used in photography).

Good on you. Everyone has to start somewhere.

Quote
I reckon 40uA is good enough. Was just saying that the ATmega32U4 could draw even less, which is good :)

Yes, 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.
I approach the thinking of all of my posts using AI in the first instance. (Awkward Irregularity)
 

Offline Mr.B

  • Supporter
  • ****
  • Posts: 1237
  • Country: nz
Re: Arduino auto power-off
« Reply #12 on: October 26, 2016, 01:43:12 am »
No need to be so aggressive

Apologies.
It was not my intention to come across that aggressive.
I approach the thinking of all of my posts using AI in the first instance. (Awkward Irregularity)
 
The following users thanked this post: rs20

Offline grifftech

  • Frequent Contributor
  • **
  • Posts: 369
  • Country: us
    • youtube channel
Re: Arduino auto power-off
« Reply #13 on: October 26, 2016, 02:53:23 pm »
use a servo motor to flip a switch between the battery and your stuff.
 

Offline rs20

  • Super Contributor
  • ***
  • Posts: 2318
  • Country: au
Re: Arduino auto power-off
« Reply #14 on: October 26, 2016, 11:17:05 pm »
use a servo motor to flip a switch between the battery and your stuff.

The more sensible version of that idea is the bistable relay.  :P
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf