Problem with my IR receiver project

Hello, I was following an Arduino Inscrutable tutorial on IR receiver + leds. The code works perfectly fine but, I’m only receiving 0’s from my remote. I would like to be able to read what buttons are being pressed. Could anyone help me with this issue? Thanks! This is the code (I didn’t make it):

#include <IRremote.h>

#define first_key 0
#define second_key 58359
#define third_key 539
#define fourth_key 25979
int receiver_pin = 11;

int first_led_pin = 7;
int second_led_pin = 6;
int third_led_pin = 5;
int fourth_led_pin = 4;

int led = {0,0,0,0};
IRrecv receiver(receiver_pin);
decode_results output;

void setup()
{
Serial.begin(9600);
receiver.enableIRIn();
pinMode(first_led_pin, OUTPUT);
pinMode(second_led_pin, OUTPUT);
pinMode(third_led_pin, OUTPUT);
pinMode(fourth_led_pin, OUTPUT);
}

void loop() {
if (receiver.decode(&output)) {
unsigned int value = output.value;
switch(value) {
case first_key:
if(led[1] == 1) {
digitalWrite(first_led_pin, LOW);
led[1] = 0;
} else {
digitalWrite(first_led_pin, HIGH);
led[1] = 1;
}
break;
case second_key:

if(led[2] == 1) {
digitalWrite(second_led_pin, LOW);
led[2] = 0;
} else {
digitalWrite(second_led_pin, HIGH);
led[2] = 1;
}
break;
case third_key:

if(led[3] == 1) {
digitalWrite(third_led_pin, LOW);
led[3] = 0;
} else {
digitalWrite(third_led_pin, HIGH);
led[3] = 1;
}
break;
case fourth_key:

if(led[4] == 1) {
digitalWrite(fourth_led_pin, LOW);
led[4] = 0;
} else {
digitalWrite(fourth_led_pin, HIGH);
led[4] = 1;
}
break;
}
Serial.println(value);
receiver.resume();
}
}

Please follow the advice on posting code given in Read this before posting a programming question in order to make your sketch easy to follow, download and test

In particular note the advice to Auto format code in the IDE and to use code tags when posting code here as it prevents some combinations of characters in code being interpreted as HTML commands such as italics, bold or a smiley character, all of which render the code useless

If the code exceeds the 9000 character inline limit then attach it to a post

Your improperly posted code is written for an older version of the IRremote library and will not work with the new version ( 3.0 +).

You can delete the current IRremote library from your sketchbook/libraries folder and use the IDE library manager to install an older version of the IRremote library (version 2.x.x)

Or modify the existing code to work with the new version of the library.

Converting your 2.x program to the 3.x version, see the[url=https://github.com/Arduino-IRremote/Arduino-IRremote] IRremote library page.[/url]

    Now there is an IRreceiver and IRsender object like the well known Arduino Serial object.
    Just remove the line IRrecv IrReceiver(IR_RECEIVE_PIN); and/or IRsend IrSender; in your program, and replace all occurrences of IRrecv. or irrecv. with IrReceiver.
    Since the decoded values are now in IrReceiver.decodedIRData and not in results any more, remove the line decode_results results or similar.
    Like for the Serial object, call IrReceiver.begin(IR_RECEIVE_PIN, ENABE_ED_FEEDBACK); or IrReceiver.begin(IR_RECEIVE_PIN, DISABLE_LED_FEEDBACK); instead of the IrReceiver.enableIRIn(); or irrecv.enableIRIn(); in setup().
    Old decode(decode_results *aResults) function is replaced by simple decode(). So if you have a statement if(irrecv.decode(&results)) replace it with if (IrReceiver.decode()).
    The decoded result is now in in IrReceiver.decodedIRData and not in results any more, therefore replace any occurrences of results.value and / or results.decode_type (and similar) to IrReceiver.decodedIRData.decodedRawData and / or IrReceiver.decodedIRData.decodedRawData.
    Overflow, Repeat and other flags are now in IrReceiver.receivedIRData.flags.
    Seldom used: results.rawbuf and results.rawlen must be replaced by IrReceiver.decodedIRData.rawDataPtr->rawbuf and IrReceiver.decodedIRData.rawDataPtr->rawlen.
    The old functions sendNEC() and sendJVC() are deprecated and renamed to sendNECMSB() and sendJVCMSB() to make it clearer that they send data with MSB first, which is not the standard for NEC and JVC. Use them to send your old 32 bit IR data codes. In the new version you will send NEC commands not by 32 bit codes but by a (constant) 8 bit address and an 8 bit command.

electronicsnoob2626:
Hello, I was following an Arduino Inscrutable tutorial

I am so hoping that’s not a typo :smiley:

Autocorrect gets it right for once?

WARNING: You don't have a 'led[4]', just 'led[0]', 'led[1]', 'led[2]', and 'led[3]'. I'm surprised the compiler didn't point that out.

Everyone's advice was very helpful, I was able to fix my problem by changing the version of my IRremote package as one of you correctly stated. Thank you for your time! :slight_smile: