[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  Electronics
. -> [Folder]  Microprocessors
. . -> [Subject]  Power-saving on Arduino Question

Power-saving on Arduino Question

Postings by administrators only.

[Refresh] Refresh page


Posted by Zajebiscie   (1 post)  [Biography] 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
[Go to top] top

Posted by Nick Gammon   Australia  (22,982 posts)  [Biography] 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
[Go to top] 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.


11,885 views.

Postings by administrators only.

[Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

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

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]