Turning Arduino on and off using momentary switch?

Hello! You know how computers, TVs, some flashlights, etc. have a momentary switch that you click once to turn it on, and once again to turn it off. So is that possible with Arduino: click once to turn the Arduino on, click again to shut off the power (momentary switch, not push on - push off switch). Is there some kind of circuit that makes that possible? Also, is it possible to do the same thing with an IR TV remote? Just out of curiosity and for convenience.

Usually the way this is done is by using a microcontroller to handle the push switch and control the main power supply to the whole device - a small amount of power is needed to run the power-switch monitoring circuit all the time.

It can be implemented in discrete CMOS logic too - but microcontrollers are more flexible and can do software-debouncing.

So to do this to an Arduino you could use another Arduino (switching a MOSFET perhaps). Not necessarily useful. There are ways to send the Arduino into sleep mode while still monitoring a pin - perhaps a better approach...

Here is one device that can do what you want:

http://www.pololu.com/catalog/product/750

Lefty

I randomly thought of this, but I did not test it. Will anything short circuit or not work, etc. if I do this?

int stayOn = 2;
int turnOff = 3;
void setup() {
  pinMode(stayOn, OUTPUT);
  digitalWrite(stayOn, HIGH);
  pinMode(turnOff, INPUT_PULLUP);  
}

void loop() {
  if(millis() > 3000 && !digitalRead(turnOff)){ //so the Arduino doesn't turn off too soon
    digitalWrite(stayOn, LOW); //turn the Arduino off
  }
}

All I would do it hold the button down until the sketch begins to run and release it. If I press it again after at least 3 seconds, the Arduino should shut off.

Curious to know how this turned out. Did you use the push button breakout that lefty pointed you to? I read the description and it seems like it would work well for that type of on-off control of an Arduino.

Thanks

If you are using a barebones atmega328p rather than an actual Arduino, then it's usually simpler to leave the chip permanently connected to the power, but put it into power-down sleep mode when you want to turn it off. This doesn't work with a full Arduino Uno or Mega because the USB-to-serial converter remains powered up. It should work ok with an Arduino Leonardo.

Hmmmm...well I am planning - at this point anyway - to use an Uno and like this concept of powering up and shutting down, partly because of the auto-shutoff feature, so I plan on trying this out and seeing how it works. Thus I was curious to know if anyone else has tried it and could share their experience.

Thanks

You can make a simple pushbuttom switch with a 4013:

http://ernstsite.wordpress.com/2-2/

Erni: You can make a simple pushbuttom switch with a 4013:

http://ernstsite.wordpress.com/2-2/

Before I got Arduino, I had this electronics kit with a 4013 counter chip and a quad NAND gate chip. There was a particular circuit that used the 4013 to flip-flop switch LEDs with push button. Thanks for reminding me!

av8or1: Curious to know how this turned out.

I am kind of scared to try it out.

dkl65:

av8or1: Curious to know how this turned out.

I am kind of scared to try it out.

I'm not. Ordered one today, will let everyone know how it works out.

Thanks

av8or1:

dkl65:

av8or1: Curious to know how this turned out.

I am kind of scared to try it out.

I'm not. Ordered one today, will let everyone know how it works out.

Thanks

No, I am talking about my random circuit.

dkl65: No, I am talking about my random circuit.

Ah ok. Sorry for the misunderstanding. Still, I will give a report later on with the thought that it might help someone else later down the road.

Good luck.

can't we enter sleep mode via the toggle? watchdog?

can’t we enter sleep mode via the toggle? watchdog?

I got the same idea, so i tryed it on an ATtiny85 and came up with this sketch
I use momentary button on PB3 and a LED on PB4.
When the led is off either by toggling the button or by the autoshutdown feature the current
consumption is 0.7 ?A (if my DVM is to be trusted)

The autoshut-down time is determined by the variable autoDown=10000;

All the sleep codes are from a resent thread
http://arduino.cc/forum/index.php/topic,164146.0.html
and Jack Christensen’s Million Ohms project.

// In sleep mode the consumption is 0,7 microA

#include <avr/sleep.h>
#include <avr/interrupt.h>

unsigned long autoDown=10000;
boolean ledState=false; 
unsigned long mtime;
volatile boolean state = HIGH;

ISR(PCINT0_vect){
  state = !state;
}

void setup(){
  pinMode(4,OUTPUT);
  GIMSK=_BV(PCIE);  //Table 9.3.2
  PCMSK=_BV(PCINT3); //Table 9.3.4
  sei();     
  mtime=millis();
}


void loop() {

  digitalWrite(4, state);

  if(state==LOW){
    gotoSleep();
  }

  if(state==HIGH){
    digitalWrite(4, state);
    if((millis()-mtime)>=autoDown){
      state=LOW;
      digitalWrite(4, state);
      gotoSleep();
      mtime=millis();
    }

  }

}


void gotoSleep(){
  ACSR |= _BV(ACD);                         //disable the analog comparator
  ADCSRA &= ~_BV(ADEN);                     //disable ADC
  set_sleep_mode(SLEEP_MODE_PWR_DOWN);  // choose your preferred sleep mode for the chip
  sleep_enable(); // this puts the chip into, sleep mode, but doesn't command it to sleep yet.
  sleep_mode();  //  this command actually puts the chip to sleep.
}

av8or1:

dkl65: No, I am talking about my random circuit.

Ah ok. Sorry for the misunderstanding. Still, I will give a report later on with the thought that it might help someone else later down the road.

Good luck.

All-

I ended up using the Maxim 16054 for the power controller on my custom board. It yields the ability for a momentary switch to provide ON/OFF power via an internal latch, as well as a CLEAR pin that enables the uC to turn itself off completely via s/w.

Anyway, it's been a while since anyone discussed the topic, but I did say that I would report back, so there it is.

http://www.maximintegrated.com/datasheet/index.mvp/id/5879

I'd have used a d-flip flop (due to how many I have)

Just throwing this out there and it might be a little over engineered but this is how I thought I would do it. I would hook up the arduino DC jack to a relay and the 5v relay connection to a pin on the arduino say ( pin 6) with code saying when the arduino turned on set that pin high. The momentary switch would send power to the arduino vin and another pin (say 7) so when pressed would power the arduino turning on the relay and the arduino would stay on. Then to turn off the arduino I would have code pin 7 to say if 5 seconds have passed since powered on when pin 7 is high make pin 6 low powering off the relay then when you let go of the momentary there is no more power and turns off....boom

It's just so much simpler to use the Polulu part.

By the powers of Google combined: