Circuit for MCU to control its own power on/off

For various reasons, i'd like my ATMega to control its own power availability, that is: to have a momentary contact push button used to switch the power on, then have the ATMega control how long the power stays on, and when it is powered off. A bit like a PC where you hold the power switch down for 4 seconds or so to do a hard power down.

I'd like the push button used for this to be capable of being sensed by the ATMega even when the system is powered up and running (so i can detect a subsequent button press).

i don't have much room on the PCB, and would prefer not to use an electromechanical relay etc., but cheap semiconductor components, or a dedicated IC if such a thing exists (i haven't been able to find a suitable one). It must have very low leakage current as i want to be able to keep the device powered down for long periods (up to a month) without running the battery down.

Does anyone know of an IC that does this, or can anyone recommend/design a circuit for this?

Many Thanks...

You would need to simply turn everything else off or into power saving mode, then sleep the avr, people have gotten their avr into the microamps range with sleeep mode

I've done this before - you have to ensure that the push switch drives a pin on the microprocessor but doesn't try to feed a voltage to it when the circuit is off (and that the current is limited while powering up).

Use a p-channel MOSFET to switch the +5V power to the processor, and a couple of CMOS NOR gates as a set/reset flip-flop. The push button line is pulled-down to ground with 10k to 100k, and push button pulls it up to 5V, triggers the flip-flop - the output from flip-flop goes low and turns on the p-channel MOSFET. The other input to the flip flop is pulled down to GND with 10k to 100k but also driven by a processor pin to provide switch-off pulse. The push-button output can be fed via 10k to 100k resistor to another pin to sense the button state while processor is running. (NOR flipflop:

So a p-channel MOSFET and a 74HC02 quad-NOR chip and some resistors - assuming I've got my logic right! All the CMOS circuitry can be permanently powered up as it will take nano-amps when quiescent (no current in the pull-downs in the off state).

ST's STM6600:

-- The Rugged Motor Driver: two H-bridges, more power than an L298, fully protected

Here is a link to a drawing that I designed using a cheap $1 single coil 5vdc low coil current latching relay I bought on E-bay to perform manual power on, auto power off. To add a manual off you would have to wire an additional pushbutton input to the arduino and do the 4 second delay and then issue a power off.

The software when it first powers up needs to set the relay output pin HIGH in the setup function. Then you can power down via software anywhere in your code you want to by just setting the output pin LOW.


MarkT: brilliant! - many thanks for this. A couple of questions:

  1. do you see any problem running this from a 3.7v LIPO to power a 3.3v system - i'm presuming not.
  2. can i put the output of this circuit directly into my regulator (MIC5205)? if so, do i need the 0.1 uF caps?
  3. given the lag in the power line coming up to voltage, might the "sense" line go high to the MCU before the power rail: could this cause problems for the MCU? (does the series resistor cover this?)
  4. am i right to think that when the battery is plugged in the NOR flip flop could power up in any state (actual power on or off), so we might want to add a cap to make sure it always comes up with the actual power off.

thanks again...

Yes, I think you are right there. 74HC family are 6V tolerant so 3.7 should be ok - its finding a p-channel MOSFET which will work at that voltage that’s an issue - must be logic level, ideally Rds(on) spec’d for <= 3.7V Vgs. If the circuit doesn’t take much power a PNP could be substituted but 74HC can’t sink very much current from the base.

And yes a cap to fix startup-state would work but you’d need another series-resistor then to limit current to controller pin.

Hi MarkT
Happy New Year
I am attempting to use a POLOLU Baby Orangutan which has an on-board ATmega 328P + TOSHIBA TB6612FNG dual H-bridge.
It appears to draw woefully large amounts of power in sleep mode so I would like to use your above power isolation circuit to resolve this (in particular I like the functionality of the “sense button” circuit).
However I do have some questions which hopefully you’ll be able to advise on.
a) Do I need to de-bounce the momentary push button? The NXP Semiconductor datasheet for Quad 2 Input NOR gates 74AHC02; 74AHCT02 states that “All inputs have a Schmitt-trigger action”, would this negate the need for de-bounce circuitry?
b) When changing batteries, you advise “a cap to fix startup-state would work but you’d need another series-resistor then to limit current to controller pin”. Can you please advise values for these components and where they should be positioned?
c) I presume you recommend placing a 0.1u cap across the flip-flop Vcc / GND and tying the spare gates to GND?
d) I intend using a FAIRCHILD Semiconductor FQP27P06 P-Channel MOSFET to switch the power, any comments on my selection of that device?
Thanks in anticipation
PS I have attached datasheets for the 74AHC02; 74AHCT02 & FQP27P06

74AHC_AHCT02.pdf (86.8 KB)

FQP27P06.pdf (747 KB)

MarkT, teabag, anyone I would greatly appreciate a response to any or all of my questions (my apologies for referencing specific manufacturers/components), however I feel sure you can answer the two main questions: a) Does the switch need to be de-bounced? b) How do I ensure the startup-state is OFF? Kind Regards RayK

Pololu makes several power switch modules that appear to do what you want.

Hi jremington Thanks for your input but the POLOLU power switch modules (or Adafruit etc) don’t offer the functionality of MarkT’s above circuit e.g. they don’t have a “sense button” that monitors a subsequent push of the momentary push button and they don’t offer a known startup-state. Regards RayK

Hi jremington

I retract my previous statements.

POLOLU do say that the default startup-state is OFF (when using supply voltages below the working upper limits).

It also appears that the modules can be configured such that a subsequent push of a button will not switch power OFF (it should just repeat power ON command).

The subsequent push will be sensed by the MCU (MCU having now been powered up from the first push of the button).