Using the On-board push button as a on/off switch

Hi everyone, Still a newbie working with the arduino trying to understand it but i was wondering how can i use the on-board push button on my Mega ADK as a on/off switch. I know i have to use a interrupt for it because it's hardwired to pin 2 and it need to essentially turn on and off when the clock changes, is it possible if some one can lead me through this?

No, you can't do it.

The button on the ADK is a reset button. It is hard wired to the reset pin, and pressing it resets the microcontroller.

I don't know that specific chip, but there may be ways to disable the reset functionality and use that pin as an input pin, but that would also disable your ability to program the board at all, so you'd be kind of stuck.

To do what you want you will need external circuitry. The chip can't turn on its own power, as there is no power to run the chip so it can turn the power on. Kind of a catch-22 situation.

You can create a soft latching power switch using a P-channel MOSFET, which has the gate pulled to Vin through a resistor, then a button pulls it down to ground to turn it on. The Arduino then takes its power from the MOSFET, and when it powers up it drives an IO pin HIGH which turns on an NPN transistor which in turn shorts out the power button keeping it turned on. You can then "release" the NPN transistor at any time by setting the IO pin LOW, which then turns off the power.

The other option is to not turn off the power, but to enter sleep mode and wake up on an interrupt. There's tutorials around the web (and on the Playground I believe) that teach you how to work with sleep mode.

Thanks for the post i thought since you can program the LED to use the push button you can probably use an interrupt to disable the power. I think the sleep mode option takes a better liking for time. Thanks again for the post

since you can program the LED to use the push button

Where did you see this ?

I'ts an example on the Arduino Site

int pin = 13;
volatile int state = LOW;

void setup()
{
  pinMode(pin, OUTPUT);
  attachInterrupt(0, blink, CHANGE);
}

void loop()
{
  digitalWrite(pin, state);
}

void blink()
{
  state = !state;
}

I have the Links as well: http://www.arduino.cc/en/Reference/AttachInterrupt#.Uw_6s_ldWAM

UP2ME4ME: Thanks for the post i thought since you can program the LED to use the push button you can probably use an interrupt to disable the power. I think the sleep mode option takes a better liking for time. Thanks again for the post

That example does not "program the LED to use the pushbutton". It uses a program to detect the pushbutton being pressed, and to then turn the LED on. In no way does it attach the pushbutton to the LED. There is no program that can physically change the wiring of the printed circuit board.

You can, of course, physically wire something external to the Arduino that could be activated by the Arduino to power it off, but once that happens, the Arduino caan no longer control the external device or itself, until it is again turned on.

UP2ME4ME: Hi everyone, Still a newbie working with the arduino trying to understand it but i was wondering how can i use the on-board push button on my Mega ADK as a on/off switch. I know i have to use a interrupt for it because it's hardwired to pin 2 and it need to essentially turn on and off when the clock changes, is it possible if some one can lead me through this?

You could use this: http://www.pololu.com/product/750

It's a solid state power switch. The Arduino could (by using one of it's pins) turn off it's own power, but of course it can't turn itself back on. Obviously if the Arduino is turned off it's not running, so no code to turn a switch on could execute, even if it could without power! :)

Right i was thinking about that.... i might as well put it into sleep mode to make things easier, thanks

I think I remember that exit is supposed to shut the processor down but I'm not completely sure:

from AVR-LibC that Arduino runs on: void exit ( int __status )

The exit() function terminates the application. Since there is no environment to return to, status is ignored, and code execution will eventually reach an infinite loop, thereby effectively halting all code processing. Before entering the infinite loop, interrupts are globally disabled.

Maybe first, run a few of the disables in the Power Reduction Management library? http://www.nongnu.org/avr-libc/user-manual/group__avr__power.html

Hmmm, if I don't use the ADC then I can save power by shutting it off......