Power-saving on Arduino Question

Posted by Zajebiscie on Sat 15 Dec 2012 08:09 AM — 2 posts, 16,558 views.

#0
Hello everyone. Please,I need help to write a program that will save life battery using Arduino.Basically,I want my Arduino to go idle when is not in use, and can be wakeup when FSR sensor is press (interrupt through pin2). Also while pressing the FSR sensor, the Arduino will remain awake but as soon FSR is release, it will go back to sleep. Furthermore,Based on my research and readings from this site, i found the topic that explored the various power-saving options running from battery power via http://www.gammon.com.au/forum/?id=11497. I followed the steps,and i put codes together but not sure if it is right way since i m still learning how to program. Please can anyone from this forum help me look into the code below and tell me what i am doing wrong..thanks

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

const byte LED = 9;

void wake ()
{
// cancel sleep as a precaution
sleep_disable();
} // end of wake

void setup ()
{
digitalWrite (2, HIGH); // enable pull-up
} // end of setup

void loop ()
{

pinMode (LED, OUTPUT);
digitalWrite (LED, HIGH);
delay (50);
digitalWrite (LED, LOW);
delay (50);
pinMode (LED, INPUT);

// disable ADC
ADCSRA = 0;

// turn off various modules
PRR = 0xFF;

set_sleep_mode (SLEEP_MODE_IDLE);
sleep_enable();

// will be called when pin D2 goes low
attachInterrupt (0, wake, LOW);

// turn off brown-out enable in software
MCUCR = _BV (BODS) | _BV (BODSE);
MCUCR = _BV (BODS);
sleep_cpu ();

// must do this as the pin will probably stay low for a while
detachInterrupt (0);

} // end of loop
Amended on Sat 15 Dec 2012 05:03 PM by Zajebiscie
Australia Forum Administrator #1
This is a cross-post of:

http://arduino.cc/forum/index.php?topic=137136

Please do not cross-post.

I have answered that question in the above thread.