Infrared decoding help

Hello I used the following arduino code from the playground to decode ir signals:

/*
 *  File....... IRanalyzer.pde 
 *  Purpose.... Records up to 128 signal changes
 *  Author..... Walter Anderson 
 *  E-mail..... wandrson@walteranderson.us 
 *  Started.... 18 May 2007 
 *  Updated.... 18 May 2007 
 * 
 *
 */ 
#include <avr/interrupt.h>
#include <avr/io.h>

#define TIMER_RESET  TCNT1 = 0
#define SAMPLE_SIZE  64

int IRpin = 2;
unsigned int TimerValue[SAMPLE_SIZE];
char direction[SAMPLE_SIZE];
byte change_count;
long time;

void setup() {
  Serial.begin(115200);
  Serial.println("Analyze IR Remote");
  TCCR1A = 0x00;          // COM1A1=0, COM1A0=0 => Disconnect Pin OC1 from Timer/Counter 1 -- PWM11=0,PWM10=0 => PWM Operation disabled
  // ICNC1=0 => Capture Noise Canceler disabled -- ICES1=0 => Input Capture Edge Select (not used) -- CTC1=0 => Clear Timer/Counter 1 on Compare/Match
  // CS12=0 CS11=1 CS10=1 => Set prescaler to clock/64
  TCCR1B = 0x03;          // 16MHz clock with prescaler means TCNT1 increments every 4uS
  // ICIE1=0 => Timer/Counter 1, Input Capture Interrupt Enable -- OCIE1A=0 => Output Compare A Match Interrupt Enable -- OCIE1B=0 => Output Compare B Match Interrupt Enable
  // TOIE1=0 => Timer 1 Overflow Interrupt Enable
  TIMSK1 = 0x00;          
  pinMode(IRpin, INPUT);
}

void loop()
{
  Serial.println("Waiting...");
  change_count = 0;
  while(digitalRead(IRpin) == HIGH) {}                                 
  TIMER_RESET;
  TimerValue[change_count] = TCNT1;
  direction[change_count++] = '0';
  while (change_count < SAMPLE_SIZE) {
    if (direction[change_count-1] == '0') {
      while(digitalRead(IRpin) == LOW) {}
      TimerValue[change_count] = TCNT1;
      direction[change_count++] = '1';
    } else {
      while(digitalRead(IRpin) == HIGH) {}
      TimerValue[change_count] = TCNT1;
      direction[change_count++] = '0';
    }
  }
  Serial.println("Bit stream detected!");
  change_count = 0;
  time = (long) TimerValue[change_count] * 4;
  Serial.print(time);
  Serial.print("\t");
  Serial.println(direction[change_count++]);
  while (change_count < SAMPLE_SIZE) {
    time = (long) TimerValue[change_count] * 4;
    Serial.print(time);
    Serial.print("\t");
    Serial.println(direction[change_count-1]);
    Serial.print(time);
    Serial.print("\t");
    Serial.println(direction[change_count++]);    
  }
  Serial.println("Bit stream end!");
  delay(2000);
}

and I had 2 problems:

  1. it kept going off without ir signal and giving me the bit string but it worked with another ir receiver code so I know the receiver is set up correctly.
  2. how do you turn the bit stream into a protocol?
    I tried the software arduino wrote about with the graphing(I believe it is called gnuplot)
    but didnt understand how to program it into arduino...

?

!

help please?

Maybe if you wrote sensible questions.

I asked questions either answer them or not
dont be a jerk

tomer1510 - there are a lot of IR-protocols out there. Have a look at IRMP – Mikrocontroller.net (In German, but for Arduino-like hardware and with a lot of links at the bottom) and at http://www.sbprojects.com/knowledge/ir/ir.htm (in English, but not that exhaustive). Some documentation of IR-protocols can also be found at http://www.lirc.org/ - this is the Linux IR project.

Basically, you need to take the timing information you are getting from the IR-sensor-chip and see what protocol is used by your IR-remote. Note that sometimes Manchester encoding is used - with is a little bit difficult to decode. Often, the code is realized by different pulse lengths, which is much easier.

Note also that you do not really need actually to decode the IR if you only want to transmit it, for example, in another room, if you want to substitute an Arduino for your remote control, or if you want to recognize only if a certain button is pushed on the remote control (and have the Arduino do something useful). Have a look at Ken Shirriff's blog Testing the Arduino IR remote library for more information.

  • cpixip

thank you very much! very helpful links

Im trying to program samsung's protocol into arduino but every database I find is missing their frequency...
is there a way to find out what it is because as I understand it is very important

tomer1510 - if you buy an IR-receiver with a 38kHz frequency (TSOP38xx or so), you should be able to decode every other frequency used, as the selectivity of these devices is not too sharp (have a look at the datasheet).

Only some exotic stuff like the Bang&Olufsen remote controls use widely different frequencies, all other manufacturers are in the vincinity of 38kHz. This is therefore ialso the frequency of most common IR-repeater systems.

Of course, you will loose some range if you are not working with the optimal frequency. So if you can find out the Samsung frequency - great. But it should work even with unmatched frequencies. - cpixip.

I know im being a pain but let me get back to my initial problem:
I used the arduino decoding code from the playground but it kept "getting ir signals" eventhough none were send...
Im using an infrared receiver that I know uses 38khz but even google havent heard of it...
and how do I put samsung protocol into the ir remote library?
p.s. im using an infrared emiter found in a well known company whos name I dont remember at the moment
and i've got 3 of them
this si the protocol:
Frequenz ?? kHz
Kodierung Pulse Distance
Frame 1 Start-Bit + 16 Daten(1)-Bits + 1 Sync-Bit + 20 Daten(2)-Bits + 1 Stop-Bit
Daten(1) 16 Adress-Bits
Daten(2) 4 ID-Bits + 8 Kommando-Bits + 8 invertierte Kommando-Bits
Start-Bit 4500µs Puls, 4500µs Pause
0-Bit 550µs Puls, 450µs Pause
1-Bit 550µs Puls, 1450µs Pause
Sync-Bit 550µs Puls, 4500µs Pause
Stop-Bit 550µs Puls
Wiederholung keine
Tasten-Wiederholung N-fache Wiederholung des Original-Frames innerhalb von 100ms
Bit-Order LSB first

and this is how I thought it should appear in the iremote library:

#define SAMSUNG_HDR_MARK 4500
#define SAMSUNG_HDR_SPACE 550
#define SAMSUNG_ONE_MARK 550
#define SAMSUNG_ZERO_MARK 550
#define SAMSUNG_RPT_LENGTH 45000
#define SAMSUNG_BITS 16

and this is the code I've used:

#include <IRremote.h>
IRsend irsend;

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

void loop() {
if (Serial.read() != -1) {
for (int i = 0; i < 3; i++) {
irsend.sendSamsung( 0x40BF, 16); //(tv power code, bits)
delay(100);
}
}
}

it is being send from pin 3 and I checked with a camera that it is transmitting something but nothing happened to the tv
what am I doing wrong?

thanks but I dont have a 1000$ or a clue of how to use it
can someone please tell me what I did wrong?

The 50MHz one is only $400

ok but before I rush to buy anything can you please tell me what I did wrong?

can you please tell me what I did wrong?

From this distance?
Probably not.

I'd probably say you've bitten off more than you can chew.

I told you exactly what I did
and gave you the protocol
please tell me what I might've done wrong

tomer1510 - "please tell me what I might've done wrong" - frankly, judging from the responses you got: not doing your homework properly...

Most of the information you are looking for can be obtained by the use of your favorite search engine. It's a great way to use the Internet for self-education.

Anyway - here are some further comments which might help you to move on:

If you are getting IR-signal even without even sending them, probably your setup and/or your magic IR-receiver are not working properly. Something like this does not happen in a normal IR-receiver/Arduino setup. You only see IR-signals from the IR-receiver if there is IR-modulation "in the air".

Well, wireing something like "Im using an infrared receiver that I know uses 38khz but even google havent heard of it..." is probably just asking for disaster.

As a first step, I'd suggest you go to a really IR-dark room, i.e. a room without any IR-equipment which might possibly transmit (no TV, no PC, no mobile phone for example) and test whether you are still receiving IR-codes.

If this is the case, try to get a decent IR-receiver (they do not cost that much, no more than $5) and get your software ready for prime time, i.e., work out whether your software is working correctly.

Try for example this receiver http://www.vishay.com/docs/82090/tsop48xx.pdf. It stays by itself absolutely silent if no IR is transmitted in a room, on the other hand, it is extremely sensible if IR-signals are present.

Now, once you have a functioning software setup with a decent sensor, you might go on and try to figure out what your magic sensor is actually delivering. Probably it's only a photodiode or -transistor, and these gadgets are of no direct use for IR-code reception - you need bandpass filtering and automatic gain to get a decent IR-signal decoded.

One last hint: in the case of IR-codes, you can simply use a PC-soundcard oscilloscope setup to see what your IR-sensor is actually receiving, even get the timing and listen to the IR-signals with your PC-loudspeakers. No need to spend $400 (probably too less) - $1000 (probably right for Arduino-based work) on an oscilloscope.

Have fun! - cpixip

No need to spend $400 (probably too less)

The 50MHz version is good for what most people will want to do with an Arduino.

OTOH, a soundcard is going to be flummoxed at 38kHz.

thanks for all the help and I will get a new well known ir receiver
(p.s. my receiver is from a tv set and it looks like an ir receiver and with a certain unrelevent software it did work)
and I tried google but still didnt understand what I did wrong with the ir emitter
a few posts ago I wrote the protocol I have found for samsunga and what I added to the irremote library
please tell me if you see anything wrong there because the emitter does emit just not the right thing