ir library is not working on stand alone mode...

i constructed standalone atmega 8 with infrared sensor(TSOP 1738)…the project is to receive IR signals from the remote and to switch on the two 5v RELAYS, i am using 16 Mhz crystal and the fuses i have written in to ATMEGA 8 are

Low fuse : 0xFF High fuse : 0xC9

FUSE BITS FOR 16MHZ CRYSTAL
http://postimg.org/image/d0dsi1071/

the code works for few mins to hours and after that,ir library fails to respond completely (or) only few buttons on remote gets detected,to make the standalone circuit work again,i have to power it off

button “A”,“B”,“C”,“D”,“E” on the remote spits two different codes at a time,so i used the two codes for those buttons in the case statement…Atmega8 doesnt have any bootloader and i used Extreme burner to burn the HEX file.

#include <IRremote.h>

int RECV_PIN = 3; // the pin where you connect the output pin of TSOP4838

int led1 = 11;
int led2 = 13;

int itsONled = {0,0,0,0};
/* the initial state of LEDs is OFF (zero)
the first zero must remain zero but you can
change the others to 1’s if you want a certain
led to light when the board is powered */

#define code1 17488 // code received from button A
#define code2 41668 // code received from button A
#define code3 60117 // code received from button B
#define code4 65321 // code received from button B
#define code5 36392 // code received from button C
#define code6 31188 // code received from button C
#define code7 59661 // code received from button D
#define code8 64865 // code received from button D

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
Serial.begin(9600); // you can comment this line
irrecv.enableIRIn(); // Start the receiver
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
}

void loop() {
if (irrecv.decode(&results)) {
unsigned int value = results.value;
switch(value) {
case code1:
case code2:
Serial.println(“in first case”);
if(itsONled[1] == 1) { // if first led is on then
digitalWrite(led1, LOW); // turn it off when button is pressed
itsONled[1] = 0; // and set its state as off
}

break;
case code3:
case code4:
Serial.println(“in second case”);
if(itsONled[1] == 0) {
// else if first led is off
digitalWrite(led1, HIGH); // turn it on when the button is pressed
itsONled[1] = 1; // and set its state as on
}
break;
case code5:
case code6:
Serial.println(“in third case”);
if(itsONled[2] == 1) { // if first led is on then
digitalWrite(led2, LOW); // turn it off when button is pressed
itsONled[2] = 0; // and set its state as off
}

break;
case code7:
case code8:
Serial.println(“in fourth case”);
if(itsONled[2] == 0) {
// else if first led is off
digitalWrite(led2, HIGH); // turn it on when the button is pressed
itsONled[2] = 1; // and set its state as on
}
break;
}
irrecv.resume(); // Receive the next value
Serial.println(value); // you can comment this line

}
}

I SOLVED MY PROBLEM.....ACTUALLY THE PROBLEM IS NOT WITH IR LIBRARY...THE PROBLEM IS WITH THE RELAY,WHICH I CONNECTED TO ATMEGA-8 OUTPUT PIN USING A TRANSISTOR (BC 547) ...

WHEN EVER THE RELAY SWITCHES ON AND OFF,THE TRANSIENT THAT PASSES THROUGH THE CIRCUIT HAS MADE ATMEGA-8 TO ENTER INTO SOME UNRESPONSIVE STATE...

SO TO PREVENT THIS RELAY NOISE ON ATMEGA-8(STANDALONE),,,I USED A OPTO-COUPLER ( 4N35) AND I ISOLATED THE CIRCUIT FURTHER BY USING TWO POWER SUPPLIES, ONE FOR ATMEGA-8 AND OTHER POWER SUPPLY FOR OPTO-COUPLER AND RELAY ..

NOW MY IR RECEIVER CIRCUIT IS WORKING WITH REMOTE WITHOUT ANY PROBLEMS

Couldn’t you just use diodes across the relay pins?