Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.
 Entire forum ➜ Electronics ➜ Microprocessors ➜ Power-saving on Arduino Question

Power-saving on Arduino Question

Postings by administrators only.

Refresh page


Posted by Zajebiscie   (1 post)  Bio
Date Sat 15 Dec 2012 08:09 AM (UTC)

Amended on Sat 15 Dec 2012 05:03 PM (UTC) by Zajebiscie

Message
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
Top

Posted by Nick Gammon   Australia  (23,120 posts)  Bio   Forum Administrator
Date Reply #1 on Sat 15 Dec 2012 08:03 PM (UTC)
Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


12,864 views.

Postings by administrators only.

Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.