Extend Battery Life with Sleep Mode

Hi, I have a project where I use arduinos inside advertising tables. We use several LEDs and a photoresistor. I have around 75 tables to install, but I need the arduino battery to last at least a a week; I am hoping this is possible. What I want is the arduino to wake up every 20 minutes, scan if there is action with the photoresistor for a couple of minutes and then go back to sleep for another 20 minutes and so on.

I am new to the Arduino world, so I have been running plenty of tests but still having trouble.

I am currently using an Arduino One with one Rayovac 9V Alcaline battery, and another battery to for the LEDs. I use to different circuits so I have transistors running each circuit from different LEDpins on the ARDUINO (8 and 9) with the ground from the LED battery going to the Arduino Ground. The circuits works very well, the LED battery does not drains out.

The link below shows one of our tables.

https://www.sugarsync.com/pf/D6610987_7918806_22553

For the program I am using the WatchDog timer to wake it up, but from what I understand I can only use it for 8 secunds, so I set up a counter for 150 times. I also tried the Narcolpetic Library but I couldnĀ“t get to sleep for more than 8 seconds.

Regarding LED program itself what I am doing is getting an average of ten light measurements from the photoresistor (because I have different light conditions in different places and times) and then setting a range, if the last reading is under that range the LED routine starts.

I have been considering using a bigger battery (like a motorcycle battery) or a 555 external timer to cut off the power.

This is my code, it is based on the nightingale program.

//???????????????????????????????????????????????????????????????????????
//???????????????????????????????????????????????????????????????????????
//???????????????????????????????????????????????????????????????????????
//???????????????????????????????????????????????????????????????????????


#include <avr/sleep.h>
#include <avr/wdt.h>

#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif

int nint;
int pinLed=13;

volatile boolean f_wdt=1;

//------------------------------------------------------

const int FotoceldaPin1 = 5;
const int ledPin8 =  8;    
const int ledPin9 =  9;   
const int ledPin10 =  10;    


int EstadoSensor1 = 0;
int var = 0; // sumatoria
int rango =0; //valor del rango del sensor de luz
int x = 0; //valor del for
int j=0;
int k = 0;
int y = 0;
int salida = 151; // para salir del ciclo

void setup() {
// initialize the LED pin as an output:
pinMode(ledPin8, OUTPUT);  
pinMode(ledPin9, OUTPUT);
pinMode(ledPin10, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(FotoceldaPin1, INPUT);

Serial.begin(9600); //ver la pantalla en PC


//???????????????????????????????????????????????

  pinMode(pinLed,OUTPUT);
  Serial.println("Setup watchdog");

  // CPU Sleep Modes
  // SM2 SM1 SM0 Sleep Mode
  // 0    0  0 Idle
  // 0    0  1 ADC Noise Reduction
  // 0    1  0 Power-down
  // 0    1  1 Power-save
  // 1    0  0 Reserved
  // 1    0  1 Reserved
  // 1    1  0 Standby(1)

  cbi( SMCR,SE );     // sleep enable, power down mode
  cbi( SMCR,SM0 );     // power down mode
  sbi( SMCR,SM1 );     // power down mode
  cbi( SMCR,SM2 );     // power down mode

  setup_watchdog(9);
 
//??????????????????????????????????????????????????
}

byte del;
int cnt;
int counter = 150; // timer for counting watchdog cicles
long time = 0;





//****************************************************************
//****************************************************************
//****************************************************************
void loop(){

  if (f_wdt==1) {  // wait for timed out watchdog / flag is set when a watchdog timeout occurs
    f_wdt=0;     // reset flag

    ///// debuging purpose only /////
    time = millis();
    Serial.print(counter);
    Serial.print(" ");
    Serial.println(time);
    delay(2); //needed for serial.print operation to finish
    /////////////////////////////////////

    if(counter==150)  // if ==10 -> this will be true every 10x8 = 80seconds; set to 225 to get 225x8=1800s = 30min
    {

     //////////////// put code inside this IF ////////

     for (k = 0; k<4; k++){
             //sacar el promedio
        for (x=0; x<10; x++) {
            EstadoSensor1 =  analogRead(FotoceldaPin1); //lee el valor de la fotocelda
            Serial.print(x); Serial.print(": "); Serial.println(EstadoSensor1);
            //delay(250);
            var = var + EstadoSensor1;
         }
            
         var = var / 10;
         Serial.print("promedio: "); Serial.println(var);
            
         rango = var - 25;
   
         Serial.print("rango: "); Serial.println(rango);
         Serial.print("K: "); Serial.println(k);
         delay(1000);            
          for (x=0; x< 150; x++){
            EstadoSensor1 =  analogRead(FotoceldaPin1); //lee el valor de la fotocelda
            Serial.print("lectura: "); Serial.println(EstadoSensor1);
            //delay(250);
              for (j=0; j<1; j++){ //repite esta accion J veces
                   if (EstadoSensor1 <=  rango) {   
                    //enciende las luces de acuerdo con el orden
                      for (y=0; y<3; y++){
                          digitalWrite(ledPin9, HIGH);
                          delay (500);
                          digitalWrite(ledPin9, LOW);
                          delay (250);
                        }
                      delay (000);
                      digitalWrite(ledPin9, HIGH);
                      digitalWrite(ledPin8, HIGH);
                      delay (2000);
                      digitalWrite(ledPin9, LOW);
                      delay(2000);       
                      digitalWrite(ledPin8, LOW);
                
                      x=salida;
                   
                       }
              }
          }
          delay (1000);
          //aqui el programa lo que realiza es un tiempo
          // se suma hasta cumplir 3 minutos aproximadamente
         
     }
    var=0;
     ////////////////////////////////////////////////////

     counter = 0;
    }
    else counter++;

    system_sleep();

  }

}


//****************************************************************
// set system into the sleep state
// system wakes up when wtchdog is timed out
void system_sleep() {

  cbi(ADCSRA,ADEN);                 // switch Analog to Digitalconverter OFF

  set_sleep_mode(SLEEP_MODE_PWR_DOWN); // sleep mode is set here
  sleep_enable();

  sleep_mode();                    // System sleeps here

    sleep_disable();                  // System continues execution here when watchdog timed out
  sbi(ADCSRA,ADEN);                 // switch Analog to Digitalconverter ON

}

//****************************************************************
// 0=16ms, 1=32ms,2=64ms,3=128ms,4=250ms,5=500ms
// 6=1 sec,7=2 sec, 8=4 sec, 9= 8sec
void setup_watchdog(int ii) {

  byte bb;
  int ww;
  if (ii > 9 ) ii=9;
  bb=ii & 7;
  if (ii > 7) bb|= (1<<5);
  bb|= (1<<WDCE);
  ww=bb;
  Serial.println(ww);


  MCUSR &= ~(1<<WDRF);
  // start timed sequence
  WDTCSR |= (1<<WDCE) | (1<<WDE);
  // set new watchdog timeout value
  WDTCSR = bb;
  WDTCSR |= _BV(WDIE);

}
//****************************************************************
// Watchdog Interrupt Service / is executed when  watchdog timed out
ISR(WDT_vect) {
  f_wdt=1;  // set global flag
}

Any ideas are welcome!!