IR remote - LED active during sleep.

Hello!

I decided some time ago to build my own remote to control both my tv and stereo and attach it to my table in front of my sofa (I always misplace my remotes).

I've got everthing working, but of course i want to minimize the power consumption since the idea is to run the thing off batteries.

The problem is that it draws way too much power during sleep (~25 mA, even more than it is awake but not sending), and i think the culprit is the IR LED. The LED is connected via a couple of resistors and a transistor to VCC, GND and pin 3. My first guess was that for some reason pin 3 got set to high during sleep, thus activating the LED, but i don't see why (I use pin 2 as interrupt pin).

My code is as follows:

#include 
#include 


#define          pre_data                 0x20df0000
#define          c_power                    0x10EF
#define          c_input                    0xD02F
#define          c_tv_radio                 0x0FF0
#define          c_q_menu                   0xA25D
#define          c_menu                     0xC23D
#define          c_guide                    0xD52A
#define          c_up                       0x02FD
#define          c_left                     0xE01F
#define          c_right                    0x609F
#define          c_down                     0x827D
#define          c_ok                       0x22DD
#define          c_return_exit              0x14EB
#define          c_info                     0x55AA
#define          c_av_mode                  0x0CF3
#define          c_vol_up                   0x40BF
#define          c_vol_down                 0xC03F
#define          c_mark_fav                 0x7887
#define          c_mute                     0x906F
#define          c_page_up                  0x00FF
#define          c_page_down                0x807F
#define          c_1                        0x8877
#define          c_2                        0x48B7
#define          c_3                        0xC837
#define          c_4                        0x28D7
#define          c_5                        0xA857
#define          c_6                        0x6897
#define          c_7                        0xE817
#define          c_8                        0x18E7
#define          c_9                        0x9867
#define          c_0                        0x08F7
#define          c_list                     0xCA35
#define          c_q_view                   0x58A7
#define          c_red                      0x4EB1
#define          c_green_stop               0x8E71
#define          c_yellow_play              0xC639
#define          c_blue_pause               0x8679
#define          c_text                     0x04FB
#define          c_t_opt_rev                0x847B
#define          c_subtitle_ffw             0x9C63
#define          c_rec                      0xBD42
#define          c_simplink                 0x7E81
#define          pre_datahk                  0xFEF1
#define          hkon                       0x03FC


#define          hkoff                      0xF906


int r1 = 9; // BLÅ/VIT
int r2 = 8; // BLÅ
int r3 = 7; // GRÖN/VIT
int r4 = 6; //ORANGE/VIT
int c1 = 12; // BRUN/VIT
int c2 = 11; // GRÖN
int c3 = 10; // ORANGE
int d1 = 2;
int d2 = 3;
int d3 = 4;
int d4 = 5;
int test = 0;
int hk;
int wakePin = 2;
int sleepStatus = 0;
IRsend irsend;

void wakeUpNow()        // here the interrupt is handled after wakeup
{
}

void setup(){
 Serial.begin(9600);
  for(int i = 10; i<13; i++){
    pinMode(i, INPUT);
  }
  for(int i = 6; i<10; i++){
   pinMode(i, OUTPUT); 
  }
  pinMode(wakePin, INPUT);
  pinMode(3, OUTPUT);
  
  attachInterrupt(0, wakeUpNow, LOW); // use interrupt 0 (pin 2) and run function
                                      // wakeUpNow when pin 2 gets LOW
}

void sleepNow(){
 set_sleep_mode(SLEEP_MODE_PWR_DOWN);   // sleep mode is set here

 sleep_enable();          // enables the sleep bit in the mcucr register
                             // so sleep is possible. just a safety pin 
 digitalWrite(3, LOW);
                             
 attachInterrupt(0,wakeUpNow, LOW); // use interrupt 0 (pin 2) and run function
                                       // wakeUpNow when pin 2 gets LOW

   
    sleep_mode();            // here the device is actually put to sleep!!
                             // THE PROGRAM CONTINUES FROM HERE AFTER WAKING UP

    sleep_disable();         // first thing after waking from sleep:
                             // disable sleep...
    detachInterrupt(0);      // disables interrupt 0 on pin 2 so the
                             // wakeUpNow code will not be executed
                             // during normal running time
                             
               
}

void sendButtonCommand(unsigned long command)
{
  if(hk == 0){
  irsend.sendNEC(pre_data + command, 32);
  delay(100);
  Serial.print("sending: ");
  Serial.println(pre_data + command,HEX);
  }
  else if(hk == 1){
    irsend.sendNEC(pre_datahk + command, 32);
  delay(100);
  }
}

void shoot(){
  digitalWrite(13, HIGH);
  pinMode(c3, INPUT);
  digitalWrite(r1, LOW);
  digitalWrite(r2, LOW);
  digitalWrite(r3, LOW);
  digitalWrite(r4, LOW);
  digitalWrite(c3, LOW);
  delay(100);
  test = 0;
  for(int x = 0; x < 100; x++){
  digitalWrite(r1, HIGH);
  if(digitalRead(c1) == HIGH){
    test = 1;
    hk = 0;
    sendButtonCommand(c_power);
  }
  else if(digitalRead(c2) == HIGH){
    test = 2;
    hk = 0;
    sendButtonCommand(c_input);
  }
  else if(digitalRead(c3) == HIGH){
    test = 3;
    sendButtonCommand(c_vol_up);
  }
 else{
  
  digitalWrite(r1, LOW);
  digitalWrite(r2, HIGH);
  if(digitalRead(c1) == HIGH){
    test = 4;
    irsend.sendNEC(0x10E03FC, 28);
  }
  else if(digitalRead(c2) == HIGH){
    test = 5;
    irsend.sendNEC(0x10EF906, 28);
  }
  else if(digitalRead(c3) == HIGH){
    sendButtonCommand(c_vol_down);
    test = 6;
  }
  else{
      digitalWrite(r2, LOW);
  digitalWrite(r3, HIGH);
  if(digitalRead(c1) == HIGH){
    test = 7;
  }
  else if(digitalRead(c2) == HIGH){
    test = 8;
  }
  else if(digitalRead(c3) == HIGH){
    test = 9;
  }
  else{
    digitalWrite(r3, LOW);
  digitalWrite(r4, HIGH);
  if(digitalRead(c1) == HIGH){
    test = 10;
  }
  else if(digitalRead(c2) == HIGH){
    test = 11;
  }
  else if(digitalRead(c3) == HIGH){
    test = 12;
  }
  else{
   test = test + 1; 
  }
  }
  }
 }

  Serial.println(test); 
  delay(100);
  }
  
  digitalWrite(r4, LOW);  
  digitalWrite(r3, LOW);
  digitalWrite(r2, LOW);
  digitalWrite(r1, LOW);
  
  delay(100);
}

void loop(){
  
  digitalWrite(wakePin, HIGH);
  pinMode(c3, OUTPUT);
  digitalWrite(c3, HIGH);
  Serial.print("sleeping...");
  delay(100);
  sleepNow();
  shoot();
}

I guess it's worth to mention that I use an arduino pro mini and the IR Library from http://www.righto.com/2009/08/multi-protocol-infrared-remote-library.html.

The best solution for the interrupt i came up with was activating the remote for 10 seconds by pressing any of the buttons on the third column, then going back to sleep. I'm aware that this is not the optimal solution, and will try using diodes to create an AND gate or something to make any button wake it up and skip the 10 sec timer (suggestions on better solutions are welcome :P)

Anyways, any ideas why the LED would go active during sleep?

dnk_: My first guess was that for some reason pin 3 got set to high during sleep, thus activating the LED, but i don't see why (I use pin 2 as interrupt pin).

Why guess? Just measure the voltage across it.

dnk_: My first guess was that for some reason pin 3 got set to high during sleep, thus activating the LED, but i don't see why (I use pin 2 as interrupt pin).

If you want to know whether the LED is being activated, watch it using your digital camera viewfinder.

Is anything connected to the serial interface? You seem to have the serial port open in this sketch.