IR remote sensor shows only '0' on serial monitor

I am a novice to Arduino Uno, I just started messing around with a kit I bought online. I am trying to receive signal from IR remote via IR sensor but I only receive '0' for every button pressed on remote.

#include<IRremote.h>


int recv_pin = 11;
IRrecv receiver(recv_pin);
decode_results results;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  receiver.enableIRIn();
}

void loop() {
  // put your main code here, to run repeatedly:
  if(receiver.decode()){
      Serial.println(results.value, HEX);
      receiver.resume();
    }
    
}

Look at some of the examples that come with the library. To find out what was received there are functions to call on the receiver object.

Your code has nothing in it to set a value on your result object which is why it's always zero.

if (receiver.decode((&results)))

Store the key code in the results variable of the decode_results struct.

wildbill:
Look at some of the examples that come with the library. To find out what was received there are functions to call on the receiver object.

Your code has nothing in it to set a value on your result object which is why it's always zero.

I tried the IRdump example which used IrReceiver.printIRResultRawFormatted() function to show IR remote input but that also didnot show any value.

Même problème pour moi. Par contre bons résultats avec IRremote version 2.8

Try this version of the code posted in the original post.

#include<IRremote.h>


int recv_pin = 11;
IRrecv receiver(recv_pin);
decode_results results;

void setup()
{
   // put your setup code here, to run once:
   Serial.begin(9600);
   receiver.enableIRIn();
}

void loop()
{
   // put your main code here, to run repeatedly:
   if (receiver.decode(&results))  // ********  added &results (a place to store the key code)
   {
      Serial.println(results.value, HEX);
      receiver.resume();
   }

}

I also use version 2.8 of the IRRemote library. Don't like the newer versions.

biaisjp, how did you manage to take up so much dead space?

I read something about a Deprecated Function Call. Check the README file that came with the IR library:

And check your compiler output for a warning like this:
"warning: 'bool IRrecv::decode(decode_results*)' is deprecated: You should use decode() without a parameter. [-Wdeprecated-declarations]"

So, OP, what version of the IRRemote library do you have installed?

groundFungus:
Try this version of the code posted in the original post.

#include<IRremote.h>

int recv_pin = 11;
IRrecv receiver(recv_pin);
decode_results results;

void setup()
{
  // put your setup code here, to run once:
  Serial.begin(9600);
  receiver.enableIRIn();
}

void loop()
{
  // put your main code here, to run repeatedly:
  if (receiver.decode(&results))  // ********  added &results (a place to store the key code)
  {
     Serial.println(results.value, HEX);
     receiver.resume();
  }

}




I also use version 2.8 of the IRRemote library. Don't like the newer versions.

biaisjp, how did you manage to take up so much dead space?

I get a warning: "bool IRrecv::decode(decode_results*)' is deprecated: You should use decode() without a parameter. [-Wdeprecated-declarations]"when i try to write receiver.decode(&results)
and i am using IRremote library version 3.0.0

Erik_Baas:
I read something about a Deprecated Function Call. Check the README file that came with the IR library:

And check your compiler output for a warning like this:
"warning: 'bool IRrecv::decode(decode_results*)' is deprecated: You should use decode() without a parameter. [-Wdeprecated-declarations]"

I changed the code as you mentioned but it is sttill shows '0' serial monitor
here is the changed code

#include<IRremote.h>
int recv_pin = 11;
decode_results results;
void setup() {
  Serial.begin(9600);
  IrReceiver.begin(recv_pin, ENABLE_LED_FEEDBACK);
}
void loop() {
  if(IrReceiver.decode()){
      Serial.println(results.value, HEX);
      IrReceiver.resume();
    }  
}
1 Like

Can you post a clear photo of your wiring? How to post images.

I installed the newest version of the IRRemote library and this simplified example words for me.

#include <IRremote.h>

const byte IR_RECEIVE_PIN = 11;

void setup()
{
   Serial.begin(115200);
   Serial.println("IR Receive test");
   IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK);
}

void loop()
{
   if (IrReceiver.decode())
   {
      Serial.println(IrReceiver.decodedIRData.command);
      IrReceiver.resume();
   }
}

Output

IR Receive test
24
3
8
8
17
72
72

Can you confirm that your remote is transmitting? Many cell phone cameras are sensitive to IR light. Press some buttons on the remote while watching the IR transmit LED with the phone camera. Do you see it flashing?

1 Like

groundFungus:
Can you post a clear photo of your wiring? How to post images.

I installed the newest version of the IRRemote library and this simplified example words for me.

#include <IRremote.h>

const byte IR_RECEIVE_PIN = 11;

void setup()
{
  Serial.begin(115200);
  Serial.println("IR Receive test");
  IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK);
}

void loop()
{
  if (IrReceiver.decode())
  {
     Serial.println(IrReceiver.decodedIRData.command);
     IrReceiver.resume();
  }
}




Output


IR Receive test
24
3
8
8
17
72
72




Can you confirm that your remote is transmitting? Many cell phone cameras are sensitive to IR light. Press some buttons on the remote while watching the IR transmit LED with the phone camera. Do you see it flashing?

Thank you for the assistance. I am able to receive from irremote now, guess my code was not good

I tried with the 2.7.0 version of the library and it worked!

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.