IR receiver Issue

I have been working with an Ir receiver for a few months now and have had one major issue. While trying to use the IRRECV demo program I do not get any results on the serial monitor. Please help me figure out if it is the wiring or the code.

!(https://forum.arduino.cc/Users/Student/Desktop/Photo on 11-1-16 at 12.01 PM.jpg)

This is the code:

#include <IRremote.h>

int RECV_PIN = 11;

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
}

void loop() {
if (irrecv.decode(&results)) {
Serial.println(results.value, HEX);
irrecv.resume(); // Receive the next value
}
delay(100);
}

Do you have the baud menu at the bottom right of the Serial Monitor set to 9600?

A very important troubleshooting technique you need to learn is adding debug serial prints so you can get an idea what’s happening. With your current code there are a number of possible issues such as:

  • Serial Monitor isn’t working
  • Printing results.value isn’t working
  • irrecv.decode(&results) is never true
  • The program is causing the Arduino to lock up before it ever prints anything.
  • The Arduino is in a constant reset loop

By adding debug prints throughout the code you can narrow down the cause of the problem:

#include <IRremote.h>

int RECV_PIN = 11;

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
  Serial.begin(9600);
  Serial.println(F("setup"));
  irrecv.enableIRIn(); // Start the receiver
}

void loop() {
  Serial.println(F("loop"));
  if (irrecv.decode(&results)) {
    Serial.print(F("results.value="));
    Serial.println(results.value, HEX);
    irrecv.resume(); // Receive the next value
  }
  delay(100);
}

When the program is working correctly you can comment out these debug statements or there are some techniques for being able to turn them on and off easily.

Please use code tags (</> button on the toolbar) when you post code or warning/error messages. The reason is that the forum software can interpret parts of your code as markup, leading to confusion, wasted time, and a reduced chance for you to get help with your problem. This will also make it easier to read your code and to copy it to the IDE or editor. Using code tags and other important information is explained in the How to use this forum post. Please read it.

To get a bit further here: Post a link to the remote control device you are using. Post a link to the IR receiver device you are using (the signal output of which you have connected to Pin 11) State what Arduino you are using.

Thanks for responding so quickly. I tried the code and got this "loop" message on the serial monitor.

ArduinoCardMan: Thanks for responding so quickly. I tried the code and got this "loop" message on the serial monitor.

So what does that tell us? That the loop is running but the results.value is never printed. So that eliminates some things from my list. Now it's down to:

  • irrecv.decode(&results) is never true

You see how useful that debugging technique can be? The problem isn't solved but by adding three lines of code the list of possible causes of the issue has been reduced from five to one. Now you know where to focus your efforts. Good luck!

What's the source of your IR signal? And how have you been 'working' with this for a few months if it doesn't work?

Pert, how would I go about making "irrecv.decode(&results) " true?

ArduinoCardMan: Pert, how would I go about making "irrecv.decode(&results) " true?

By sending correct data that can be decoded. There can be thousands of reasons why it returns false. Battery of the remote flat (likely if it used to work before)?

And please do not ignore posts by others (reply #2 and reply #5); answer them.

INTP the source of my of my IR signal is an infrared remote. By “working” I mean that I have trying over and over again to make it work.

Nothing is being received. Logical first step is to make sure anything is even being transmitted. Look straight onto your remote's LED through a phone camera as you push the remote's buttons. Do you see light flickering?

And please show what IR receiver you have. Need to rule out that you're actually using a proper IR receiver and not just an IR sensing diode.