IR receiver value completely random.

I recently used my IR remote + receiver module for the first time in a fairly large project of mine. It was easy to set up and use - there were no problems. I switched to an IR receiver I pulled off of an old PCB so I didn't use the other one up. It also worked with no problem.
All of a sudden, however, it just stopped working. I had a relay connected to the power button of the remote (when you clicked the button the relay would latch on/off) and one day it just stopped flicking the relay.
I hadn't changed any code or wiring - it just stopped working. The first thing I did was serial print the value. Instead of getting this:

16753245
16753245
16753245
16753245
16753245
16753245
.......

('16753245' is the code for the power button) I got this:

-20184
-5143
8639
15381
1443
19509
-28142
20460
-14129
-598
-12218
-1870
32366
-23194
-1
7399
11959

Now, clearly, something is wrong here. How can the value be so different each time? (It happens with all buttons on the remote)
I started by changing the remote I was using - still had the same problem.
I then changed back to the old receiver - still the problem.
I switched digital pins - no change, still problematic.
I had recently added in some code which I had clashing problems with - FastLED - (it affected the relay and made it freak out). Even though I thought that was the only problem I still went ahead and removed the code. It made no difference.

I did some research on it and a lot of answers were saying something about the frequencies not matching. If this is the case, why did it work perfectly for so long in the beginning?

What is happening here and how can I fix it?
Thanks,
Dream

I forgot to include my code so here it is:

#include <IRremote.h>
//#include <FastLED.h>


#define NUM_LEDS 143
int BRIGHTNESS = 100;
#define LED_TYPE WS2811
#define COLOR_ORDER GRB
#define UPDATES_PER_SECOND 100
#define AUDIO_AMP_IN 0
#define AUDIO_PEAK_IN 1

#define DIGI_POT_STEP 4
#define DIGI_POT_CS 5
#define LED_STRIP_PIN 6
#define POWER_RELAY 7
#define RECIEVER_PIN 8
#define RECIEVED_LED 9
#define PROGRAMMING_LED 10
#define PROGRAMMING_BUTTON 11

bool areLedsPowered = true;
bool called = false;

int default_values[5] = {16753245, 25245, -22441, -8161, -28561};
int new_values[5] = {};

int index, value;

int power = default_values[0];
int brightness_up = default_values[1];
int brightness_down = default_values[2];
int gain_up = default_values[3];
int gain_down = default_values[4];

int wait = 200;
unsigned long time_now_reciever = 0;
unsigned long time_now_blink_1 = 0;
unsigned long time_now_blink_2 = 0;

static uint8_t startIndex = 0;
uint16_t currentTime = 0;
uint16_t startTime = 0;
bool timing = false;

IRrecv irrecv(RECIEVER_PIN);
decode_results results;

//CRGB leds[NUM_LEDS];
//CRGBPalette16 currentPalette;
//TBlendType    currentBlending;

void setup()
{
  //delay(2000);
  pinMode(POWER_RELAY, OUTPUT);
  digitalWrite(POWER_RELAY, HIGH);

  //FastLED.addLeds<LED_TYPE, LED_STRIP_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
  //FastLED.setBrightness(BRIGHTNESS);

  //currentPalette = RainbowColors_p;
  //currentBlending = LINEARBLEND;

  Serial.begin(9600);
  irrecv.enableIRIn();
}

void loop()
{

  if (digitalRead(PROGRAMMING_BUTTON) == 0) {
    called = false;
    if (irrecv.decode(&results))
    {
      int value = results.value;
      Serial.println(value);
      blink_led(RECIEVED_LED);
      decode_value(value);
      irrecv.resume();
    }

  }
  else if (digitalRead(PROGRAMMING_BUTTON) == 1) {
    program_reciever();
  }

  //RainbowShift();
}

void RainbowShift() {
  //startIndex = startIndex + 1;
  //FillLEDsFromPaletteColors( startIndex);

  //FastLED.show();
  //FastLED.delay(1000 / UPDATES_PER_SECOND);
}

//void FillLEDsFromPaletteColors( uint8_t colorIndex)
//{
//  for ( int i = 0; i < NUM_LEDS; i++) {
//    leds[i] = ColorFromPalette( currentPalette, colorIndex, 255, currentBlending);
//    colorIndex += 3;
//  }
//}

void program_reciever() {
  if (!called) {
    called = true;
    index = 0;

    power = default_values[0];
    brightness_up = default_values[1];
    brightness_down = default_values[2];
    gain_up = default_values[3];
    gain_down = default_values[4];

    blink_led_twice(PROGRAMMING_LED);
    while (index < 5 && digitalRead(PROGRAMMING_BUTTON) == 1) {
      if (irrecv.decode(&results)) {
        value = results.value;
        new_values[index] = value;
        blink_led_twice(PROGRAMMING_LED);
        index++;
        irrecv.resume();
      }
    }
    blink_led_three(PROGRAMMING_LED);

    power = new_values[0];
    brightness_up = new_values[1];
    brightness_down = new_values[2];
    gain_up = new_values[3];
    gain_down = new_values[4];
  }
}

void program(int value) {

}

void decode_value(int value) {
  if (value == power) { //power button
    led_strip_power();
  }
  else if (value == brightness_up) {
    if (BRIGHTNESS < 100) {
      BRIGHTNESS++;
    }
    //FastLED.setBrightness(BRIGHTNESS);
  }
  else if (value == brightness_down) {
    if (BRIGHTNESS > 0) {
      BRIGHTNESS--;
    }
    //FastLED.setBrightness(BRIGHTNESS);
  }
  else if (value == gain_up) {
  }
  else if (value == gain_down) {
  }
}

void blink_led_three(int pin) {
  blink_led(pin);
  delay(100);
  blink_led(pin);
  delay(100);
  blink_led(pin);
}

void blink_led_twice(int pin) {
  blink_led(pin);
  delay(100);
  blink_led(pin);
}

void led_strip_power() {
  Serial.println("hl");
  if (areLedsPowered) {
    digitalWrite(POWER_RELAY, LOW);
    areLedsPowered = false;
  }
  else {
    digitalWrite(POWER_RELAY, HIGH);
    areLedsPowered = true;
  }
}

void blink_led(int pin) {
  digitalWrite(pin, HIGH);
  delay(100);
  digitalWrite(pin, LOW);
}

BATTERY ?

raschemmel:
BATTERY ?

What do you mean by 'battery'? is there supposed to be one?

What do you mean by 'battery'? is there supposed to be one?

If it's a "remote", what do you think it runs on ? (your good looks ?)

DUDE, is it SOLAR POWERED or what ?

raschemmel:
If it's a "remote", what fo you think it runs on ?
(your good looks ?)

DUDE, is it SOLAR POWERED or what ?

Oh right - you meant the remote! Of course there's a battery in the remote!

And ?

Did you REPLACE it ?

raschemmel:
And ?

Did you REPLACE it ?

Unfortunately, I cant replace it. I don't have the batteries - it uses a 2025 and I only have 2023's.
I don't see why I need to replace it. I haven't even used it for a total of 1 day.

int default_values[5] = {16753245, 25245, -22441, -8161, -28561};

How can you place 16753245 into an ‘int’.

Maybe you should use ‘unsigned long’ :wink: .

“I don't see why I need to replace it.”

To rule out that it might be the problem.

I thought you were posting because your remote wasn't working any more.
Just how do you think batteries work ?
Do you think that because it worked yesterday that the battery cannot run out between yesterday and today ? How does that work ?

Did you at least measure the voltage on the battery ?

Is the voltage >3.00 Volts ?

raschemmel:
I thought you were posting because your remote wasn't working any more.
Just how do you think batteries work ?
Do you think that because it worked yesterday that the battery cannot run out between yesterday and today ? How does that work ?

Did you at least measure the voltage on the battery ?

Is the voltage >3.00 Volts ?

I can see where you misunderstood. I never said my remote stopped working - it almost seems that the decoder in the IR library is not working. I could be wrong - that's why I wanted help. Why are the values so random?
I did try with a different remote, but as I said, it didn't work.

int default_values[5] = {16753245, 25245, -22441, -8161, -28561};

How can you place 16753245 into an 'int'.

Maybe you should use 'unsigned long' :wink: .

larryd:
int default_values[5] = {16753245, 25245, -22441, -8161, -28561};

How can you place 16753245 into an 'int'.

Maybe you should use 'unsigned long' :wink: .

I have changed them now.

Ok, this is weird. I was doing some more debugging and it is working again now. The values that show up on button press are always the same now, instead of being random. The only thing that changed is the actual values:
16753245 used to be the code for the power button.
Now 23971 is the code. So it has changed. Why did it do this and will it do it again? As you can see in my code I want to have default values but if the default values are always changing then I can't use them.

EDIT: nevermind, only the power button value changed. All the others stayed the same.

So it has changed. Why did it do this and will it do it again?

Now you have corrected the mistake it should stay the same. Before with the mistake in it the code was writing over memory locations it should have not been accessing. This was causing you to see a false number.