Detecting code of IR remote

Hello everyone,

I'm very new to arduino and coding so the question may seem very naive
I'm trying to find the code my IR remote send when I press a button. I'm using this remote, and plugged it following the recommandation of the manufacturer
https://www.reichelt.com/fr/en/arduino-8211-infrared-remote-kit-ard-ir-remote-p282671.html?CCOUNTRY=443&LANGUAGE=fr&GROUPID=9020&START=0&OFFSET=16&SID=9259b0282e3b16a34ecf307921d1950c07626fe55dca53095ed02&LANGUAGE=EN&&r=1

I've tried several codes for it, the one that works best is :

#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);
}

But when I go to "serial monitor" and press any button it always send me the code "FFFFFFFF". I read that it is because the button has been pressed for too long, but I don't think so

Do you have any idea of how to solve it ?

By advance, thank you ! :slight_smile:

The code you have shown here is just the sample code of that kit (anyway, it's a generic code for IR signal analyse) so it should work. I don't know if that specific remote sends FFFFFF as the "repeat" signal like some other remotes do, but at least the first line (the first time you press a button) it should print a specific code, to be "repeated" when receiving FFFFFF.

What exact version of IRremote library you have? Have you tried one of the examples (like ReceiveDump)?

This is an NEC remote.

image

Try

#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)) {
  if(results.value != 0xFFFFFFFF)
   {
    Serial.println(results.value, HEX);
   }
    irrecv.resume(); // Receive the next value
  }
  delay(100);
}


Always show us a good schematic of your proposed circuit.
Show us a good image of your ‘actual’ wiring.


There is a newer version of the IR library available that you should update to.

Try the ReceiveDemo of the IRremote library and you will be lucky.

decode_results results;

Any code that has that line is written for an older version (< 3.0) of the IRremote library and is not guaranteed to run with the newer versions of the library. if you have the newer version (< 3.0) of the library installed, take the advice of @ArminJo and try the library examples. Also read the documentation for the newer version to see the differences from old versions.

I've download the last version of the IR library and tried your code, but this time nothing appears at all when I press a button on the remote...
Even so there's still a little red light next to the IR diode that turns on every time I press a button

I just tried several examples of the IR remote library (including ReceiveDemo), and this time things like this appears when I press a button : H⸮P⸮⸮⸮⸮(JAp>⸮⸮@⸮Vp⸮⸮⸮_⸮⸮e͆⸮⸮T⸮6))⸮⸮⸮?S⸮⸮
But sometime I have to press several times to have something, and it is not always the same characters

Are you sure that the serial monitor baud rate is set the same as the Serial.begin function in the example code?

Please, always include the code corresponding to the output/behaviour you're talking about. without it, we can't say anything except just guesses.

Anyway, that looks like a Serial Monitor speed mismatch. Check the value of Serial.begin() with the Serial Monitor baud setting. They must be exactly the same.

Yes it was 9600 for both the serial monitor baud and the Serial.begin fonction in the code.
I just tried several serial monitor baud (making it match with the code ligne every time), and the one that worked best is 19200 baud, but when I press the same button several times I've got differents numbers each time :
A3523300
923CFC35
640D992E
4149D525
6C792022
FFFFFFFF
FFFFFFFF
FFFFFFFF
FFFFFFFF
FFFFFFFF

Here's the code I used this time :

/*
 * 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(19200);
  irrecv.enableIRIn(); // Start the receiver
}

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

Make sure your remote’s coin cell is new.

Yes I used a new one...

The rubbish you posted on Post#7 doesn't say that, except for loose cables damaging the communications, it's typically a speed mismatch.

If 19200 baud works is good to let you go on with debugging the code, but it looks like you have serial issues of unknown kind (for me), as there are no reasons to have such bad serial communication for lower/different speeds, I have never had problems like that you described. I suspect you need to check your USB serial connection and USB driver. What are the OS and IDE versions you're using? What serial USB driver have you installed? What happens if you open the (virtual) serial with any other serial terminal (like putty)?

What is exactly your IRremote library version?
And for a better and more detailed data output (the code you're using is too "basic"), please use "ReceiveDump" code you can find amongst the library examples, and show here the results of the tests (pressing one single button a few times at 1 second distance, then keep pressing it for a second).

I've shown the code to a friend of mine that works on the eletronic field and does a lot of arduino programming. He made me change the code to this :

#include "IRremote.hpp"
int RECV_PIN = 11; // define input pin on Arduino
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);
Serial.println (results.value, DEC);
Serial.println (results.value, BIN);
irrecv.resume (); // Receive the next value

// Print Raw Data

 IrReceiver.printIRResultShort(&Serial);
}
}

And when we pressed the button this appears :

09:55:54.662 -> FFFFFFFF
09:55:54.710 -> 4294967295
09:55:54.710 -> 11111111111111111111111111111111
09:55:54.758 -> Protocol=UNKNOWN Hash=0x0 34 bits (incl. gap and start) received
09:55:54.805 -> FFFFFFFF
09:55:54.805 -> 4294967295
09:55:54.853 -> 11111111111111111111111111111111
09:55:54.853 -> Protocol=UNKNOWN Hash=0x0 2 bits (incl. gap and start) received

So he's thinking maybe the problem is more linked to the remote I ordered... I've order a new one, it should arrive on friday. I hope it will work this time !

Hello. With the new remote, now it work, doesn't it?

Hope to see your reply because i got the same problem.

Hello,

I had to buy no more than 3 IR remote and receiver to find something that works...
Anyway I manage to do it with a Keyes receiver, and a CarMP3 remote using this code :

#include<IRremote.h>

IRrecv IR (11);



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

void loop() {
  // put your main code here, to run repeatedly:
if(IR.decode()){
  Serial.println(IR.decodedIRData.decodedRawData,HEX);
  delay(1500);
  IR.resume();
}
}

It looked like something like that :

With (from left to right)
The first wire on GND; second on 5V; and last on 11

I wish you good luck with your code !

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