IR sensor not receiving

I am trying to find the button codes for my IR remote using my Arduino UNO. I got this code from Instructables. The button code is supposed to appear in the serial monitor, but nothing shows up. I am almost positive that I connected the wires to the right place. I did not get any error messages. Thanks in advance😄!

Here is my code:

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
    }
}

Your topic was MOVED to its current forum category which is more appropriate than the original as it has nothing to do with Installation and Troubleshooting of the IDE

The code you posted is only part of the complete sketch.... above that code box is:

#include <IRemote.h> 

which you will need to paste into the top of your sketch... then try running it again.

Instructables seems to have zero error checking, and more often the projects are missing something... and sadly, so is create.arduino.cc... but you have this forum to help you get your stuff working.

Thanks! I will add the code and let you know if it works.

Still no luck :frowning:. I think it has something to do with the code, rather than the hardware. I even tried it in Tinkercad's circuit simulator with the same schematics and code, but it still didn't work.

Please post your revised sketch and a schematic of your project. A 'photo of a hand drawn circuit is good enough

Here is my schematic:


and here is my code:

#include <IRremote.h>
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
    }
}

That is not a schematic unless the pins on the IR module are labelled.

Did you choose to use pin 12 for a reason ?

Is that the pin that the library expects you to use ?

You can check the IR Receiver by connecting a LED with a 1K resistor between the terminal marked out and 5volts. It will flash when you operate the remote control.
Be aware that the pinouts of those IR receiver types are not all the same so check the data sheet.

Oops! I should have used pin 11. Sorry!

We forgive you! But MCU's are heartless.

I did what you said, but the LED doesn't blink when you press a button. It just stays off.

Post your complete revised sketch

I just tried it in the Tinkercad simulator and it works in there :thinking:

You can also view a transmitting IRLED by pointing your "phone" (in camera mode) at the TXIRLED.

Try this sketch

/*
 * IRremote: IRrecvDemo - demonstrates receiving IR codes with IRrecv
 * An IR detector/demodulator must be connected to the input RECV_PIN.
 * Version 0.1 July, 2009
 * Copyright 2009 Ken Shirriff
 * http://arcfn.com
 */

#include <IRremote.h>

int RECV_PIN = 11;

IRrecv irrecv(RECV_PIN);

decode_results results;

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

void loop() {
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    Serial.println(results.value);
    
    if (results.value == 0xFF00FF)
    {
      Serial.println("!");
    }
    irrecv.resume(); // Receive the next value
  }
}

Thanks, but I just got a bunch of question marks in the serial monitor.

It's working! Change your baud rate, either on your IDE or in your code.

(p.s. A note to the mods: The forum bot is telling me this issue has been solved in post #10.)