Keeping an Arduino on as long as a button is pushed

Hi All,

I need a little help. How can I have my arduino stay on as long as I am pushing a button and when I release it the arduino goes to sleep?

I am looking to use this code to confirm that the button is being pushed

while (status_button == HIGH){
button_delay++;
delay(100);
status_button = digitalRead(inputPin);
}

but how do I put it to sleep once the button is released?

Any help is welcomed!

Is that just for the sake for it ?

can you tell us a bit more about the real problem you are trying to solve? (and how you plan to wake up the arduino)

if you want to know how to sleep, there is a tutorial for this

Hi J-M-L,

A little bit about the problem I am trying to solve: I am having the arduino execute a number of activities while the button is pushed. Once the tasks have made it to a certain point based on my discretion, I will release the button and the ardunio needs to go to sleep.

As for your question to how I plan to wake the ardunio up, it should wake up when I push the button again. The button should be like a power button.

D

As for your question to how I plan to wake the ardunio up, it should wake up when I push the button again. The button should be like a power button.

do you have to memorize any state? because then you can just use a button controlling power to the arduino.. when you release the button it won't sleep, will just be off.

if you need to maintain some memory or complete task at hand when you release before going to sleep, then probably easiest way to do so is check at each iteration of the loop the status of the button and if it is released, set up the interrupt to wake up the arduino and go to sleep, and on wake up remove the interrupt.

Thank you for the reference and guidance!