Arduino Forum

Using Arduino => General Electronics => Topic started by: AJKnoch on Feb 17, 2013, 08:34 pm

Title: Receiving Different IR Codes From Same Remote/Button
Post by: AJKnoch on Feb 17, 2013, 08:34 pm
I am working on a project that detects what button was pressed and displays it on a LCD screen.

I am using this library for handling receiving the IR codes: https://github.com/shirriff/Arduino-IRremote

Everytime I press the same button on my Time Warner Cable remote I get different results.

What is the cause of this and how can I account for it?

Code: [Select]
#include <IRremote.h>

int RECV_PIN = 11;

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn();
}

void loop() {
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    irrecv.resume();
  }
}
Title: Re: Receiving Different IR Codes From Same Remote/Button
Post by: JimboZA on Feb 17, 2013, 08:40 pm
Are you sure it's always different?

I found that I got two different codes with some buttons, and it alternated between the two.

For example the "down" button produces either a 1041 or 3089 and I just used the || (the "or") in my code like this:

Code: [Select]
   if (results.value == 1041 || results.value == 3089)
      {
         // do stuff
      }
Title: Re: Receiving Different IR Codes From Same Remote/Button
Post by: AJKnoch on Feb 17, 2013, 08:45 pm
I just pressed the same button 25x and these are the values I received,

3653895 - 14 Times
421066283 - 1 Time
615415119 - 2 Times
604317718 - 2 Times
1358155102 - 1 Time
35434315 - 1 Time
609534435 - 2 Times
325791992 - 2 Times
Title: Re: Receiving Different IR Codes From Same Remote/Button
Post by: JimboZA on Feb 17, 2013, 08:48 pm
Ok, you got me stumped there. No idea why that could be, but I have limited experience of using the IR I must say.
Title: Re: Receiving Different IR Codes From Same Remote/Button
Post by: AJKnoch on Feb 17, 2013, 08:52 pm
It has stumped me too. I have tried multiple different remotes and they all work like expected with only one code per button but this Time Warner Cable remote keeps sending different values...
Title: Re: Receiving Different IR Codes From Same Remote/Button
Post by: JimboZA on Feb 17, 2013, 08:55 pm
Perhaps it's some kind of proprietary security thing, where the receiver can unravel the "arbitrary" string and act on it, without having to know in advance what strings might arrive. But then, why does the one string score 14/25....

Title: Re: Receiving Different IR Codes From Same Remote/Button
Post by: AJKnoch on Feb 17, 2013, 09:38 pm
So there really isn't a way to get a 100% recognition rate for the codes?
Title: Re: Receiving Different IR Codes From Same Remote/Button
Post by: JimboZA on Feb 17, 2013, 09:46 pm
Well you could do your 25 click test a few more times until you think you have seen them all, and then "or" them like I had above.

But it could just simply be that the remote you have doesn't work on the "one button- one (or two) code" principal? Have you any documentation on what that remote is supposed to produce?
Title: Re: Receiving Different IR Codes From Same Remote/Button
Post by: AJKnoch on Feb 17, 2013, 10:25 pm
I am not sure where I would find that information. The booklet that it came with is available here: http://www.universalremote.com/resources/pdfs/UR5U-8520L.pdf  but there's no information on such and I'm not sure where else to look.
Title: Re: Receiving Different IR Codes From Same Remote/Button
Post by: JoshD on Feb 17, 2013, 10:35 pm
Try this sketch to spit out a nicely formatted list of on/off pulses in microseconds:

https://github.com/smokeyser/Remote2/blob/master/Contrib/rawirdecode.ino (https://github.com/smokeyser/Remote2/blob/master/Contrib/rawirdecode.ino)

It's just the ir decode sketch from adafruit.com with a function added (printpulses3) which spits out the pulses in array format that can be copied and fed into the IRremote lib's sendRaw function.  You can take a look at the rest of the project if you want to see how I used it.  The issue you're experiencing may be more obvious when you look at the received signals in a less condensed format, though.

Around here the cable company (comcast) has started to use the XMP protocol which makes decoding a bit trickier.  I had no luck reading it with adafruit's ir sensor and had to order a new one from digi-key that supports XMP.  So if changing the formatting of the output doesn't help solve/spot the problem, you may want to google your remote and find out if it's using XMP or some other protocol.  FWIW, you don't really need to be able to properly decode their protocol.  You just need to understand it well enough to get a good signal recording that you can duplicate.

Oh, one last thing...  The ir decoders from vishay are pretty sensitive. If that's what you're using, you may want to wire it up according to the datasheet's example with the cap and resistor to clean up the output a little if you haven't done that already.
Title: Re: Receiving Different IR Codes From Same Remote/Button
Post by: fungus on Feb 18, 2013, 03:56 am

Are you sure it's always different?

I found that I got two different codes with some buttons, and it alternated between the two.

For example the "down" button produces either a 1041 or 3089 and I just used the || (the "or") in my code like this:


Yep. This is so you can tell when the user lifts his finger and presses the same button again (as opposed to holding the button down and sending the same code multiple times).

Title: Re: Receiving Different IR Codes From Same Remote/Button
Post by: JimboZA on Feb 18, 2013, 03:57 am
Quote
you don't really need to be able to properly decode their protocol....


True.... but he does need to know that he's covered all the possibilities with enough testing to ensure that in a few weeks a button doesn't generate a code he didn't see in testing and thus didn't cater for.

I guess that's what you meant by:

Quote
understand it well enough to get a good signal recording that you can duplicate
Title: Re: Receiving Different IR Codes From Same Remote/Button
Post by: fungus on Feb 18, 2013, 03:59 am

I just pressed the same button 25x and these are the values I received,

3653895 - 14 Times
421066283 - 1 Time
615415119 - 2 Times
604317718 - 2 Times
1358155102 - 1 Time
35434315 - 1 Time
609534435 - 2 Times
325791992 - 2 Times



Maybe it's because the receiver frequency doesn't match the transmitter frequency very well so you get glitches (IR remotes don't all use the same modulation frequency).

Title: Re: Receiving Different IR Codes From Same Remote/Button
Post by: JimboZA on Feb 18, 2013, 04:12 am
Quote
Maybe it's because the receiver frequency doesn't match the transmitter frequency very well


Good point: when I bought my 38 receiver, they shop had 37.5 as well.
Title: Re: Receiving Different IR Codes From Same Remote/Button
Post by: fungus on Feb 18, 2013, 04:59 am

Quote
Maybe it's because the receiver frequency doesn't match the transmitter frequency very well


Good point: when I bought my 38 receiver, they shop had 37.5 as well.


My VISHAY IR receiver datasheet lists variants at 30, 33, 36, 36.7, 38, 40 and 56 kHz. They use a bandpass filter so there's a bit of tolerance but maybe that remote is transmitting at 33 or 40kHz.

PS: You could hook an oscilloscope to the transmitter LED to find out...

Title: Re: Receiving Different IR Codes From Same Remote/Button
Post by: afremont on Feb 18, 2013, 08:41 am

I just pressed the same button 25x and these are the values I received,

3653895 - 14 Times
421066283 - 1 Time
615415119 - 2 Times
604317718 - 2 Times
1358155102 - 1 Time
35434315 - 1 Time
609534435 - 2 Times
325791992 - 2 Times



Well that can't be right in my opinion.  Since the new library was just released on the 16th, I suspect you are looking at a bug.

It's been a little while, but I've looked at well over a dozen different remote controls on a scope and with linux.  I have never seen anything that should result in differences like that.  It's common for the protocol to flip a bit between transmissions or even send a final code after you let up from holding the key.  I never saw anything that would be that difficult to cope with.  Something seems amiss, but try a different remote control if you can.
Title: Re: Receiving Different IR Codes From Same Remote/Button
Post by: runningdude22 on Mar 12, 2013, 02:39 am
Did you ever get a solution here? I'm trying the exact same thing--And seeing, as you did, different values each time.
Title: Re: Receiving Different IR Codes From Same Remote/Button
Post by: afremont on Mar 12, 2013, 08:34 am

Did you ever get a solution here? I'm trying the exact same thing--And seeing, as you did, different values each time.


What kind of remote are you using?  I have the same problem myself now with the U-verse remote.  I did some digging, and I think the problem is that the remote is sending more than 32 bits which seems to freak out the library.  I saw where somebody said they made a change in the library somewhere and worked for them, but I don't know any more than that.  I'd like to fix mine too, so keep this thread alive if you find a solution.
Title: Re: Receiving Different IR Codes From Same Remote/Button
Post by: runningdude22 on Mar 12, 2013, 03:04 pm
Supposedly Samsung remotes use 38kHz. When I use the IR library I have to output raw codes to see them with my Samsung remote. It works--I see codes--but they are different every time. Any suggestions?
Title: Re: Receiving Different IR Codes From Same Remote/Button
Post by: runningdude22 on Mar 12, 2013, 03:06 pm
@afremont --Its a samsung remote for my Time Warner DVR box. When I output raw codes I can see them just fine. After some digging it does appear that the samsung remote is using 38kHz carrier frequency, which would be compatible with the IR receiver I am using-- https://www.sparkfun.com/products/10266
Title: Re: Receiving Different IR Codes From Same Remote/Button
Post by: afremont on Mar 12, 2013, 04:35 pm
Even if you were off frequency several kHz, it would still work with reduced range is all.  So you are saying that the RAW values (strings of CSV numbers that are negative and positive integers) are consistently received?  If so, I believe you can have the library send the data from that format, but it still doesn't help you receive them.  It sounded like a simple change to raise the number of bits to 64 from the post I read.  Of course, after glancing thru the code, I didn't see it that way.  They had left an important piece out of their post; namely which specific format to modify.



Title: Re: Receiving Different IR Codes From Same Remote/Button
Post by: fungus on Mar 12, 2013, 04:57 pm
I've seen "universal" remotes that broadcast several different codes for each button press (hoping one of them will work, presumably). Maybe that's the problem.

It would be easy to see if you connect an oscilloscope to the leg of the IR receiver.
Title: Re: Receiving Different IR Codes From Same Remote/Button
Post by: JoshD on Mar 12, 2013, 06:31 pm
Keep in mind that those short numbers are just the library's attempt at figuring out an unknown protocol and condensing it into a more manageable form.  If it's not working, you'll need to take a look at the unencoded version of the signal.  If you look at it in raw on/off pulse times, patterns should emerge.  The code could be too long, it could be sending in two short bursts, or you could have even found a bug.  You won't know until you look at the actual signal and figure out why it isn't being handled properly.
Title: Re: Receiving Different IR Codes From Same Remote/Button
Post by: runningdude22 on Mar 13, 2013, 02:42 am
I just discovered something--if I am too close to the sensor (3 feet), I get inconsistent results. 5 or so feet and I get consistent results. Odd.
Title: Re: Receiving Different IR Codes From Same Remote/Button
Post by: runningdude22 on Mar 13, 2013, 01:43 pm
Following up:
http://matthewrupert.net/2013/03/13/arduinoir/
Title: Re: Receiving Different IR Codes From Same Remote/Button
Post by: ChirantanKansara9 on Jun 30, 2014, 05:13 am
I am using the IR remote sensor library.  Everything works fine. Now I want that when I press my KEY numbered ' 1 ' on IR remote and successively press the other e.g. volume + , what should be done to to read this complete procedure.
Title: Re: Receiving Different IR Codes From Same Remote/Button
Post by: akeom on Oct 15, 2014, 12:01 am
Hi, same problem here. Following experiment:

- I commented out nearly all of my main loop
- after that, I could receive the right button-pressed codes
- uncommented main loop ->> same problem again.

I think it might be a performance issue at the arduino. I use an arduino mini pro 5v 16MHz
Library is  "IRremote.h" and I'm controlling DC motors with the IR

Here's my output with thin Main Loop, "Other Button" is the #fail condition
Opening port
Port open
IR Receiver Raw Data + Button Decode Test
255
other button   
16736925
VUp             
16736925
VUp             
16736925
VUp             
16736925
VUp             
16712445
VDown           
4294967295
other button   
16712445
VDown           
4294967295
other button   
16712445
VDown           
4294967295
other button   
4294967295
other button   
4294967295
other button   
16720605
VSlower           
16720605
VSlower           
4294967295
other button   
16761405
VFaster     
10
4294967295
other button   
4294967295
other button   
4294967295
other button   
16761405
VFaster     
10
16761405
VFaster     
10
16761405
VFaster     
10
16748655
HFaster           
16748655
HFaster           
16754775
HSlower         

Here the same sequence with "THick " main Loop:
Port open
IR Receiver Raw Data + Button Decode Test
1253111733
other button   
3219426777
other button   
3622325019
other button   
5316027
other button   
4001918335
other button   
4001918335
other button   
713775392
other button   
3810010651
other button   
3810010651
other button   
4202145195
other button   
3499001667
other button   
5316027
other button   
5316024
other button   
176854242
other button   
2098956842
other button   
4001918335
other button   
4001918335
other button   
5316027
other button   
2603687621
other button   
3887428328
other button   
851901943
other button   
1223062238
other button   
268228494
other button   
3789458290
Title: Re: Receiving Different IR Codes From Same Remote/Button
Post by: Ajay_Abi on Oct 28, 2015, 05:46 pm
Hi I am ajay.
I am beginner in arduino software. I just want to know the code for ir receiver, i am having arduino uno board along with TSOPSM0038 IR Receiver i just want to know the coding for this program can any one help me please.
Title: Re: Receiving Different IR Codes From Same Remote/Button
Post by: Vaupell on Dec 31, 2015, 11:09 pm
Well an old post, and it seems to be a common problem..

For future reference ;)

Often the problem is cheap shit from a company called "keyes" they
produce a ton of crabby sensors and other stuff to sell to new players..


I once had a similar problem, i solved it by using a old TV-Remote.
Using a high quality remote like the ones that comes with your TV, ensures a steady, constant ir signal.

Where the cheap ones can change value, depending on the angle between the receiver and sender.
...

Use a program to read your TV remote keys and then reprogram your software to use it.
Title: Re: Receiving Different IR Codes From Same Remote/Button
Post by: smoker414 on Feb 20, 2016, 12:22 am
For me the solution was using 9v battery instead of using power from the computer to the usb of the arduino
Title: Re: Receiving Different IR Codes From Same Remote/Button
Post by: iancon on Feb 20, 2016, 11:28 pm
I have some cheap remotes (http://www.aliexpress.com/item/Free-Shipping-10LOT-Infrared-IR-Wireless-Remote-Control-Module-Kits-For-Arduino-Wholesale/32596278113.html?spm=2114.30010308.3.10.zpDooA&ws_ab_test=searchweb201556_1,searchweb201644_4_505_506_503_504_502_10001_10002_10017_10010_10005_10011_10006_10003_10004_10009_10008,searchweb201560_2,searchweb1451318400_-1,searchweb1451318411_6452&btsid=b7b221fc-2df4-4c5d-890c-f16becad9a05) from china  - they give inconsistent results as well (what a surprise)  I think that the main problem with these is one of the clocking in the cheap remotes.

After a bit of debugging and looking at the data stream it appears that the remote is giving a reasonable result, but the tolerance that the library tries when decoding an unknown data stream is too high.  By opening the tolerance I am now getting a consistent result.

Here is the extract from irRecv.cpp

//+=============================================================================
// hashdecode - decode an arbitrary IR code.
// Instead of decoding using a standard encoding scheme
// (e.g. Sony, NEC, RC5), the code is hashed to a 32-bit value.
//
// The algorithm: look at the sequence of MARK signals, and see if each one
// is shorter (0), the same length (1), or longer (2) than the previous.
// Do the same with the SPACE signals.  Hash the resulting sequence of 0's,
// 1's, and 2's to a 32-bit value.  This will give a unique value for each
// different code (probably), for most code systems.
//
// http://arcfn.com/2010/01/using-arbitrary-remotes-with-arduino.html
//
// Compare two tick values, returning 0 if newval is shorter,
// 1 if newval is equal, and 2 if newval is longer
// Use a tolerance of 20% - changed to 40%
//

int  IRrecv::compare (unsigned int oldval,  unsigned int newval)
{
   if      (newval < oldval * .6)  return 0 ;
   else if (oldval < newval * .6)  return 2 ;
   else                            return 1 ;
}
Title: Re: Receiving Different IR Codes From Same Remote/Button
Post by: ffpbar on Mar 06, 2016, 09:06 am
Same problem here. Different readings every time. By the way; almost ALL remotes are made in China.
Title: Re: Receiving Different IR Codes From Same Remote/Button
Post by: aarg on Mar 06, 2016, 09:47 am
A timely post, as I was consternated at the reluctance of my remote (cheap Chinese universal remote). I'm actually getting very similar timings but they are decoded differently, for example:
Code: [Select]
Encoding  : NEC
Code      : 33B8609F (32 bits)
Timing[67]:
     +8950, -4500     + 500, - 600     + 500, - 600     + 500, -1750
     + 500, -1700     + 550, - 600     + 500, - 600     + 500, -1700
     + 550, -1700     + 550, -1700     + 500, - 600     + 550, -1700
     + 500, -1700     + 550, -1700     + 500, - 600     + 550, - 600
     + 500, - 600     + 500, - 600     + 550, -1700     + 500, -1700
     + 550, - 600     + 500, - 600     + 500, - 600     + 500, - 600
     + 550, - 600     + 500, -1700     + 550, - 600     + 500, - 600
     + 500, -1750     + 500, -1700     + 500, -1750     + 500, -1700
     + 550, -1700     + 500

Encoding  : UNKNOWN
Code      : 9866EE37 (32 bits)
Timing[67]:
     +8950, -4500     + 500, - 600     + 500, - 650     + 500, -1700
     + 500, -1700     + 550, - 600     + 500, - 600     + 500, -1700
     + 550, -1750     + 500, -1700     + 500, - 600     + 550, -1700
     + 500, -1700     + 550, -1700     + 500, - 600     + 550, - 600
     + 500, - 650     + 450, - 650     + 500, -1700     + 500, -1750
     + 500, - 600     + 500, - 600     + 500, - 600     + 500, - 650
     + 500, - 600     + 500, -1750     + 500, - 600     + 500, - 600
     + 500, -1750     + 500, -1700     + 500, -1750     + 500, -1700
     + 550, -1700     + 500

Encoding  : JVC
Code      : 33B8 (16 bits)
Timing[67]:
     +8950, -4450     + 550, - 550     + 550, - 600     + 500, -1700
     + 550, -1700     + 500, - 600     + 500, - 600     + 550, -1700
     + 500, -1750     + 500, -1700     + 550, - 600     + 500, -1700
     + 550, -1700     + 500, -1700     + 550, - 600     + 500, - 600
     + 500, - 600     + 550, -1700     + 500, - 600     + 550, -1700
     + 500, - 600     + 500, - 600     + 550, - 600     + 500, - 600
     + 500, - 650     + 500, - 600     + 500, -1700     + 500, - 600
     + 550, -1700     + 500, -1750     + 500, -1700     + 550, -1700
     + 500, -1750     + 500

These were received a few seconds apart, pointing the remote at the ceiling. I changed the tolerance in compare(), as suggested in reply #30, to 50% but it doesn't seem much better:
Code: [Select]
Encoding  : NEC
Code      : 33B8A05F (32 bits)
Timing[67]:
     +8950, -4500     + 500, - 600     + 500, - 600     + 550, -1700
     + 500, -1700     + 550, - 600     + 500, - 600     + 500, -1700
     + 550, -1700     + 550, -1700     + 500, - 600     + 550, -1700
     + 500, -1750     + 500, -1700     + 500, - 600     + 550, - 600
     + 500, - 600     + 500, -1750     + 500, - 600     + 500, -1750
     + 500, - 600     + 500, - 600     + 500, - 600     + 550, - 550
     + 550, - 600     + 500, - 600     + 550, -1700     + 500, - 600
     + 500, -1750     + 500, -1700     + 550, -1700     + 500, -1750
     + 500, -1700     + 550

Encoding  : JVC
Code      : 33B8 (16 bits)
Timing[67]:
     +8950, -4500     + 500, - 600     + 500, - 600     + 500, -1750
     + 500, -1700     + 550, - 600     + 500, - 600     + 500, -1700
     + 550, -1700     + 550, -1700     + 500, - 600     + 500, -1750
     + 500, -1700     + 550, -1700     + 500, - 600     + 500, - 600
     + 550, - 600     + 500, -1700     + 550, - 600     + 500, -1700
     + 550, - 550     + 550, - 600     + 500, - 600     + 500, - 600
     + 500, - 650     + 500, - 600     + 500, -1700     + 550, - 600
     + 500, -1700     + 550, -1700     + 500, -1700     + 550, -1700
     + 500, -1750     + 500

Encoding  : UNKNOWN
Code      : A0F5DAD5 (32 bits)
Timing[67]:
     +8950, -4500     + 500, - 600     + 500, - 600     + 500, -1750
     + 500, -1700     + 550, - 650     + 450, - 600     + 500, -1700
     + 550, -1700     + 550, -1700     + 500, - 600     + 500, -1750
     + 500, -1700     + 550, -1700     + 500, - 600     + 500, - 600
     + 550, - 600     + 500, -1750     + 500, - 600     + 500, -1700
     + 550, - 550     + 550, - 600     + 500, - 600     + 500, - 600
     + 500, - 650     + 500, - 600     + 500, -1700     + 550, - 600
     + 500, -1700     + 550, -1700     + 500, -1700     + 550, -1700
     + 500, -1750     + 500

Hmmmmm..... is it really a 64 bit code? Based on persistent use, the "NEC" code is the correct decode.

Update - from the link given above http://www.righto.com/2010/01/using-arbitrary-remotes-with-arduino.html (http://www.righto.com/2010/01/using-arbitrary-remotes-with-arduino.html), I get
Quote
If your remote uses a protocol with multiple duration values, you probably won't get unique values from this algorithm.
I see three values in the timings so maybe that's it. But looking at the algorithm, I can't see why there should be such a difference. Am I missing something obvious?
Title: Re: Receiving Different IR Codes From Same Remote/Button
Post by: aarg on Mar 06, 2016, 11:23 pm
Update - I disabled all known protocols in the header file and it decodes perfectly as an UNKNOWN type. So the next question would be - why does it get tricked into falsely accepting the codes as NEC, JVC? I did try tightening the spec to 0.95 while I was experimenting but that didn't work. At least, I have it working for what I need.
Title: Re: Receiving Different IR Codes From Same Remote/Button
Post by: ffpbar on Mar 07, 2016, 07:26 am
In my case, the remote wasn't the problem, but the receiver was. I had different readings all the time. With every remote. Includig the expensive ones. So I tryed a different IR reciever. That wordked. No different readings anymore. So I suggest you change the IR reciever.
Title: Re: Receiving Different IR Codes From Same Remote/Button
Post by: aarg on Mar 07, 2016, 07:41 am
In my case, the remote wasn't the problem, but the receiver was. I had different readings all the time. With every remote. Includig the expensive ones. So I tryed a different IR reciever. That wordked. No different readings anymore. So I suggest you change the IR reciever.
Not necessary. I have been getting extremely similar raw readings every time. You can see that if you look at the raw IR dumps I posted above. It is only the 32 bit hash value that was screwed up. Since I disabled the manufacturers protocols as I described above, the same receiver works flawlessly every time.

The present question is, why do the decode functions for the manufacturers protocols fail so badly, generating false positives with this transmitter? By the way, for reference, it's the Senlian RM-408C.
Title: Re: Receiving Different IR Codes From Same Remote/Button
Post by: bmossade on Jan 29, 2017, 08:53 am
Update - I disabled all known protocols in the header file and it decodes perfectly as an UNKNOWN type. So the next question would be - why does it get tricked into falsely accepting the codes as NEC, JVC? I did try tightening the spec to 0.95 while I was experimenting but that didn't work. At least, I have it working for what I need.
could you please explain to me how to do this? Thanks.
Title: Re: Receiving Different IR Codes From Same Remote/Button
Post by: Ziplock9000 on Feb 06, 2017, 06:36 pm
Well an old post, and it seems to be a common problem..

For future reference ;)

Often the problem is cheap shit from a company called "keyes" they
produce a ton of crabby sensors and other stuff to sell to new players..


I once had a similar problem, i solved it by using a old TV-Remote.
Using a high quality remote like the ones that comes with your TV, ensures a steady, constant ir signal.

Where the cheap ones can change value, depending on the angle between the receiver and sender.
...

Use a program to read your TV remote keys and then reprogram your software to use it.
So the problem was with crappy sensors from Keyes, but you solved the problem by not replacing the sensor, but a different transmitter.. That doesn't make sense.
Title: Re: Receiving Different IR Codes From Same Remote/Button
Post by: Glumgad on Mar 07, 2017, 08:18 pm
Hi, guys,
Have the same problem

So the problem was with crappy sensors from Keyes,
If the problem was with "crappy sensors", could anybody recommend some good sensors, please?  
Title: Re: Receiving Different IR Codes From Same Remote/Button
Post by: Arman Meradi on May 06, 2017, 02:45 pm
Hello guys!  I have a question about the IR receiver whitch I have salvaged from and old VCR,

I have connected it to my Arduino and its signal pin is normally HIGH, and when I press any button than it

goes LOW, is it suppoesed to be like that? and if yes than what signals does matter the LOW's or the HIGH's?

I would really apreciate it if anyone could give me a little advice about this subject. thank you.
Title: Re: Receiving Different IR Codes From Same Remote/Button
Post by: pravindesai100 on Jun 24, 2017, 05:50 am
i'm also facing this problem , when i'm doing my first IR project.....but it happens only with my cheap chinese remote , when i tried with panasonic viara remote it works very well..and gives same signal (code) every time ........
Title: Re: Receiving Different IR Codes From Same Remote/Button
Post by: INTP on Jun 24, 2017, 07:05 am
TV remotes always send the same codes per button. Inconsistent readings can be caused by distance or using the wrong protocol to interpret.
Title: Re: Receiving Different IR Codes From Same Remote/Button
Post by: JustJustin on Oct 02, 2017, 05:51 am
I'm using a Panasonic DVD remote and it's doing the same thing.
Title: Re: Receiving Different IR Codes From Same Remote/Button
Post by: JustJustin on Oct 02, 2017, 06:26 am
I also just tried with an IR remote app, and it's doing the same thing.
Is this a problem with my receiver? Or maybe some sort of interference with my wiring?
Title: Re: Receiving Different IR Codes From Same Remote/Button
Post by: kabinx on Nov 05, 2017, 04:33 pm
I had the same issues.
I could "fix" it by changing the voltage to 3.3 V and decreasing the distance for the cheap remote.
Other remotes (e. g. Onkyo Receiver) work just fine with 3.3 V but not always with 5. The LED on the Arduino board blinks regularly, instead of the irregular blinking while using the cheap remote.
Title: Re: Receiving Different IR Codes From Same Remote/Button
Post by: Rnubi on Apr 17, 2018, 09:38 pm
I know this is an old thread but I think I have something to add for anyone that is struggling with errant remote codes.

I am using the 'Keyes' cheapo remotes currently and was getting some random numbers.

I found that my standard desk work lamp (halogen incandescent bulb) was pointing directly at the IR receiver and after repeat tests was effecting the receiver.

After I pointed the main 'beam' away from my project, remote and receiver worked almost flawlessly.

TL;DR  Consider your ambient lighting!

Rnubi :D
Title: Re: Receiving Different IR Codes From Same Remote/Button
Post by: Armorican on Oct 07, 2018, 12:30 am
I come years too late to help the original user, but it may help a novice having the same issue:
ground related issues will cause erratic and random like readings. Make sure your Arduino and your peripherals share the same ground.
Title: Re: Receiving Different IR Codes From Same Remote/Button
Post by: Manbearpig73 on Oct 23, 2018, 02:28 pm
I have to admit when I read post #46 I said "No way" but unbelievably that worked for me. I have tried 3 original Yamaha, Samsung and LG remotes, a Harmony universal and I Xiaomi IR blaster and all gave me random output all the time. I moved the power for my IR receiver from the breadboard to the Arduino Uno and everything started working. I have tried everything from getting new IR receivers to new remotes and it turned out to be such a simple thing like using the same ground. Armorican you a true hero in my book.
Title: Re: Receiving Different IR Codes From Same Remote/Button
Post by: turboto on Oct 30, 2018, 02:51 pm
Hello to Everyone!
I had the same problem. Now is fixed!
Do not direct lighting the sensor! Just use a reflector like a mirror. Or just use your hand at 45 degree.
             =>   The sensor is here
1111
111 1                        Your hand/reflector
 11
          \\
          _()_
           \   \                           The remote
            \   \
             \   \
              ----
I receive the same codes!



You can try another way also:
Put a sheet /try with two sheets also/ of white paper between the remote and the sensor. This will works like a filter.


SUCCESS!
Title: Re: Receiving Different IR Codes From Same Remote/Button
Post by: Josh780 on Nov 21, 2018, 06:25 am
Hi, same problem here. Following experiment:

- I commented out nearly all of my main loop
- after that, I could receive the right button-pressed codes
- uncommented main loop ->> same problem again.
I am observing the same behavior. After a few hours of debugging, I've found that I'm able to retain the majority of my original main loop() commands, provided I insert a delay() call of at least ~200ms. With this, I don't see perfect interpretation of the IR signals, but at least half of them are received correctly. I'm wondering if it's a timing issue, where if the IR signal is received while the loop() function is processing other data, it somehow jumbles the result. This makes me curious if it is a performance issue or whether the IRremote library could be modified to halt other processing as soon as it starts receiving a signal. I'm not an expert with Arduino, but I would have thought an interrupt-driven event would do this anyway.

Does anyone have any suggestions?

As background, what I'm trying to accomplish is control of an LED strip using the FastLED library, then altering the LED sequence with an IR remote. So far all I've implemented is brightness control, but if I can get this working, there's a whole slew of features I'd like to add.

For reference, here's my code:
Code: [Select]

#include "IRremote.h"
#include <FastLED.h>

#define LED_PIN     6
#define NUM_LEDS    150
#define LED_TYPE    WS2812B
#define COLOR_ORDER RGB
CRGB leds[NUM_LEDS];

#define UPDATES_PER_SECOND 100

CRGBPalette16 currentPalette;
TBlendType    currentBlending;

// set up global variable for tracking LED brightness, initially set to half-power
uint8_t brightness = 128;
#define BRIGHTNESS_INCR 16

#define IR_PIN 11  // Signal Pin of IR receiver to Arduino Digital Pin 11

/*-----( Declare objects )-----*/
IRrecv irrecv(IR_PIN);     // create instance of 'irrecv'
decode_results results;      // create instance of 'decode_results'

/*-----( Function )-----*/
void translateIR() // takes action based on IR code received
{
 // describing Remote IR codes
 switch(results.value)
 {
   case 0xFFA25D: Serial.println("POWER"); break;
   case 0xFFE21D: Serial.println("FUNC/STOP"); break;
   case 0xFF629D: Serial.println("VOL+");
     if (255 - brightness < BRIGHTNESS_INCR) {
       brightness = 255;
     } else {
       brightness += BRIGHTNESS_INCR;
     }
     Serial.println(brightness);
     break;
   case 0xFF22DD: Serial.println("FAST BACK");    break;
   case 0xFF02FD: Serial.println("PAUSE");    break;
   case 0xFFC23D: Serial.println("FAST FORWARD");   break;
   case 0xFFE01F: Serial.println("DOWN");    break;
   case 0xFFA857: Serial.println("VOL-");
     if (brightness < BRIGHTNESS_INCR) {
       brightness = 0;
     } else {
       brightness -= BRIGHTNESS_INCR;
     }
     Serial.println(brightness);
     break;
   case 0xFF906F: Serial.println("UP");    break;
   case 0xFF9867: Serial.println("EQ");    break;
   case 0xFFB04F: Serial.println("ST/REPT");    break;
   case 0xFF6897: Serial.println("0");    break;
   case 0xFF30CF: Serial.println("1");    break;
   case 0xFF18E7: Serial.println("2");    break;
   case 0xFF7A85: Serial.println("3");    break;
   case 0xFF10EF: Serial.println("4");    break;
   case 0xFF38C7: Serial.println("5");    break;
   case 0xFF5AA5: Serial.println("6");    break;
   case 0xFF42BD: Serial.println("7");    break;
   case 0xFF4AB5: Serial.println("8");    break;
   case 0xFF52AD: Serial.println("9");    break;
   case 0xFFFFFFFF: Serial.println(" REPEAT");break;  
   default:
     Serial.println(" other button  ");
     
   }// End Case
   Serial.println(results.value, HEX);

 delay(200); // Do not get immediate repeat
} //END translateIR

void setup()   /*----( SETUP: RUNS ONCE )----*/
{
 // LED Setup
 delay( 3000 ); // power-up safety delay
 FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
 FastLED.setBrightness( brightness );
 currentPalette = RainbowColors_p;
 currentBlending = LINEARBLEND;

 // IR Setup
 Serial.begin(9600);
 Serial.println("IR Receiver Button Decode");
 irrecv.enableIRIn(); // Start the receiver
}/*--(end setup )---*/


void loop()   /*----( LOOP: RUNS CONSTANTLY )----*/
{
 if (irrecv.decode(&results)) { // have we received an IR signal?
   translateIR();
   irrecv.resume(); // receive the next value
 }
 delay(200);
 
 static uint8_t startIndex = 0;
 startIndex = startIndex + 1; /* motion speed */
 FillLEDsFromPaletteColors( startIndex);
 FastLED.show();
 FastLED.delay(1000 / UPDATES_PER_SECOND);
}/* --(end main loop )-- */

// Function to actually set LED colors
void FillLEDsFromPaletteColors( uint8_t colorIndex)
{
   // uint8_t brightness = 255;
   
   for( int i = 0; i < NUM_LEDS; i++) {
       leds[i] = ColorFromPalette( currentPalette, colorIndex, brightness, currentBlending);
       colorIndex += 3;
   }
}
Title: Re: Receiving Different IR Codes From Same Remote/Button
Post by: DReam2L on Jun 07, 2019, 11:20 am
Hi All, same problem here too.

I took few minutes to test the turboto technic, and it's works, the buttons begin to send the same number on the monitor.(certainly enough to find the correct number, not yet sending test at time, AC remote)

Thanks turboto
Title: Re: Receiving Different IR Codes From Same Remote/Button
Post by: TomaszNowak on Jun 24, 2019, 03:35 am

I think I solved that problem.


I used to have the same problem with IRremote library - codes were inconsistent for most of the times (I was be able to receive the same code 3 times out of 5).

I've read all posts under this topic. I tried 3 different "cheap" remotes (one from Arduino starter kit, two controlling some disco lights) as well as TV Samsung remote; I bought different receiver - nothing helps.

So I've started looking at library implementation. Someone here suggested to remove all Remote Control definitions other than default - it didn't help. I tried to change tolerance under IRrecv::compare - also didn't help...

But what I noticed library is using kind of weird hash of output values to calculate final result.

So I printed raw data from signals.rawbuf and I imported them into Excel.
After painting them on graph I've noticed they're pretty consistent for every key press.

So long story short instead of using signals.value I'm calculating my own 64bit integer in following way:


Code: [Select]


#define IR_TOLERANCE 17


if (irrecv.decode(&signals))
{

    uint64_t irVal = 0;
    for(int i=3; i<(signals.rawlen-1); i++)
    {
        int Delta = signals.rawbuf[i] - signals.rawbuf[i+1];
        if (Delta < 0) Delta = -Delta;
        uint8_t b = (Delta < IR_TOLERANCE) ? 0 : 1;

        if ((i-3) < 63)
        {
            irVal = irVal | ((int64_t)b << (int64_t)(i-3));
        }
    }

    uint64_t x1 = irVal;
    uint32_t x = x1 >> 32;
    Serial.print(x, HEX);
    x = x1 & 0xFFFFFFFF;
    Serial.println(x, HEX);
   
    irrecv.resume(); // get the next signal
  }
 



End of it is pretty complicated because Arduino compiler doesn't want to print x64 integer.

I defined IR_TOLERANCE for 17, you can try to lower it if it's still not consistent.


Sometimes (very rare in my case) I'm receiving wrong code. But it doesn't really matter - 99% is good.


PS. Someone should update that library... :)

Tomasz