I am trying to develop a low power project, and my goal is to use as little power as possible for my arduino (328 or ATTiny 2313, I havnt decided yet). My project will have some 10 I/O pins used (with a maximum of 8 on at a single time), as well as ise an I2C bus for a DS1307 timer chip.
Is there any way I can sleep the arduino (Keeping any pins I need HIGH), for 60 seconds at a time (update arduino every minute)?? Basically, the pins that are HIGH are going to be connected to low power leds (consuming some 500 microamps each), and any other unused pins can be pulled any way needed. I want to try to estimate my time for the size of batttery, so if you could post approximate Microcontroller power usage, that would be AMAZING. Thanks so much in advance!!
After looking at some of that, and some threads on google, I built some code....
here it is..
#include <avr/sleep.h>
void wake ()
{
// cancel sleep as a precaution
sleep_disable();
} // end of wake
//****************************************************************
void setup(){
pinMode(A3, OUTPUT);
pinMode(A2, OUTPUT);
pinMode(A1, OUTPUT);
pinMode(A0, OUTPUT);
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
pinMode(10, OUTPUT);
pinMode(9, OUTPUT);
pinMode(8, OUTPUT);
digitalWrite(A3, HIGH);
digitalWrite(A2, HIGH);
digitalWrite(A1, HIGH);
digitalWrite(A0, HIGH);
digitalWrite(13, HIGH);
digitalWrite(12, HIGH);
digitalWrite(11, HIGH);
digitalWrite(10, HIGH);
digitalWrite(9, HIGH);
digitalWrite(8, HIGH);
digitalWrite(2, HIGH);
}
//****************************************************************
void loop(){
// TO "see" the leds related to I/O 12 and 13 ON
delay(1000);
// Default behavior: put all I/O pins into input mode and internal pull-up
int i;
for(i=0; i<=A5;i++)
{
if (i ==LOW) {
pinMode(i, INPUT);
digitalWrite(i, HIGH);
}
}
// disable ADC
ADCSRA = 0;
set_sleep_mode (SLEEP_MODE_PWR_DOWN);
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);
}
Basically I stole (borrowed) the code from another source, but it WORKS!!!! My circuit now says I am consuming 0.8 mA while running 10 LEDs (at 50-75 uA per LED). The arduino consumes about 7ma while active. Apparently my blue LEDs i got from tayda electronics are super-low power and put out a pretty visible (if you are looking at it) @ 50 microamps (was really surprised, a red LED took around 10ma). SWEET POWER REDUCTION!!!