Mitsubishi IR AC remote decoding Problem

@pndtkd …first of all run this sktech and post your output

#include <avr/interrupt.h>
#include <avr/io.h>

#define TIMER_RESET  TCNT1 = 0
#define SAMPLE_SIZE  232

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

ok arslankhan....this is my output pushing ON:

Analyze IR Remote
Waiting...
Bit stream detected!
0   0
3536    0
3536    1
5184    1
5184    0
5648    0
5648    1
6912    1
6912    0
7368    0
7368    1
8636    1
8636    0
9116    0
9116    1
9496    1
9496    0
9960    0
9960    1
10364   1
10364   0
10824   0
10824   1
11232   1
11232   0
11692   0
11692   1
12960   1
12960   0
13460   0
13460   1
13828   1
13828   0
14284   0
14284   1
14688   1
14688   0
15196   0
15196   1
16416   1
16416   0
16920   0
16920   1
18144   1
18144   0
18652   0
18652   1
19016   1
19016   0
19520   0
19520   1
20744   1
20744   0
21244   0
21244   1
21612   1
21612   0
22116   0
22116   1
22484   1
22484   0
22988   0
22988   1
24216   1
24216   0
24700   0
24700   1
25940   1
25940   0
26444   0
26444   1
26812   1
26812   0
27268   0
27268   1
28540   1
28540   0
28992   0
28992   1
30256   1
30256   0
30760   0
30760   1
31124   1
31124   0
31588   0
31588   1
31992   1
31992   0
32496   0
32496   1
33720   1
33720   0
34180   0
34180   1
34584   1
34584   0
35088   0
35088   1
35452   1
35452   0
35956   0
35956   1
37176   1
37176   0
37640   0
37640   1
38044   1
38044   0
38504   0
38504   1
38912   1
38912   0
39372   0
39372   1
39784   1
39784   0
40244   0
40244   1
40652   1
40652   0
41112   0
41112   1
41516   1
41516   0
42024   0
42024   1
42384   1
42384   0
42844   0
42844   1
43248   1
43248   0
43736   0
43736   1
44116   1
44116   0
44604   0
44604   1
44984   1
44984   0
45484   0
45484   1
45848   1
45848   0
46352   0
46352   1
46720   1
46720   0
47204   0
47204   1
47588   1
47588   0
48088   0
48088   1
48456   1
48456   0
48960   0
48960   1
49328   1
49328   0
49788   0
49788   1
50192   1
50192   0
50652   0
50652   1
51052   1
51052   0
51560   0
51560   1
51924   1
51924   0
52380   0
52380   1
52792   1
52792   0
53248   0
53248   1
53656   1
53656   0
54112   0
54112   1
54520   1
54520   0
55028   0
55028   1
55392   1
55392   0
55892   0
55892   1
56256   1
56256   0
56764   0
56764   1
57124   1
57124   0
57612   0
57612   1
57992   1
57992   0
58456   0
58456   1
58860   1
58860   0
59324   0
59324   1
59732   1
59732   0
60196   0
60196   1
61460   1
61460   0
61964   0
61964   1
63188   1
63188   0
63652   0
63652   1
64052   1
64052   0
64512   0
64512   1
65772   1
65772   0
66236   0
66236   1
66644   1
66644   0
67108   0
67108   1
67524   1
67524   0
68028   0
68028   1
69248   1
69248   0
69760   0
69760   1
70980   1
70980   0
71440   0
71440   1
71844   1
71844   0
72304   0
72304   1
72712   1
72712   0
73216   0
73216   1
73580   1
73580   0
74088   0
74088   1
74444   1
74444   0
74952   0
74952   1
75316   1
75316   0
75776   0
75776   1
76184   1
76184   0
76644   0
76644   1
77920   1
77920   0
78380   0
78380   1
79644   1
79644   0
80108   0
80108   1
80512   1
80512   0
80976   0
80976   1
82240   1
82240   0
82700   0
82700   1
83104   1
83104   0
83612   0
83612   1
83972   1
83972   0
84476   0
84476   1
84840   1
84840   0
85300   0
85300   1
86560   1
86560   0
87024   0
87024   1
88288   1
88288   0
88752   0
88752   1
89156   1
89156   0
89616   0
89616   1
90024   1
90024   0
90484   0
90484   1
90888   1
90888   0
91352   0
91352   1
92616   1
92616   0
93120   0
93120   1
94340   1
94340   0
94804   0
94804   1
95208   1
95208   0
95668   0
95668   1
96072   1
96072   0
96536   0
96536   1
96940   1
96940   0
97444   0
97444   1
97812   1
97812   0
98320   0
98320   1
98688   1
98688   0
99148   0
99148   1
99548   1
99548   0
100008  0
100008  1
100416  1
100416  0
100920  0
100920  1
101280  1
101280  0
101788  0
101788  1
102148  1
102148  0
102612  0
102612  1
103012  1
103012  0
103476  0
103476  1
103880  1
103880  0
104344  0
104344  1
104748  1
104748  0
105228  0
105228  1
105620  1
105620  0
106080  0
106080  1
106480  1
106480  0
106964  0
106964  1
107352  1
107352  0
107816  0
107816  1
108220  1
108220  0
108684  0
108684  1
109088  1
109088  0
109592  0
109592  1
109960  1
109960  0
110420  0
110420  1
110832  1
110832  0
111292  0
111292  1
111696  1
111696  0
112208  0
112208  1
112572  1
112572  0
113072  0
113072  1
113444  1
113444  0
113900  0
113900  1
114312  1
114312  0
114772  0
114772  1
115176  1
115176  0
115636  0
115636  1
116044  1
116044  0
116504  0
116504  1
116912  1
116912  0
117372  0
117372  1
117772  1
117772  0
118280  0
118280  1
118644  1
118644  0
119104  0
119104  1
119512  1
119512  0
120016  0
120016  1
120380  1
120380  0
120840  0
120840  1
121248  1
121248  0
121704  0
121704  1
122116  1
122116  0
122572  0
122572  1
122984  1
122984  0
123444  0
123444  1
123848  1
123848  0
124308  0
124308  1
124716  1
124716  0
125176  0
125176  1
Bit stream end!

Cybernetician:
@ arslankhan and diegt

On last weekend i was blackout due to office workload, thats why i start capturing of IR code of my friend Mitsubishi RC and got the same result by putting the value of rawbuf equal to 255

#define RAWBUF 255

When rawbuf equal to 400

#define RAWBUF 400

or greater than 255 i got the garbage result of IR sample. This is the starting point of story “There is some problem with RAWBUFF value”. Ok, First step write/stole some code to capture the IR pulses by using interrupt.

http://ucexperiment.wordpress.com/2012/02/14/reverse-engineering-an-aim-ir-beacon-transmitter/

And by viewing the code it is clear i need the modification in two lines

/*

IR Capture
 Copyright 2012, all rights reserved.
 James M. Eli
 1/14/2012

project parts:
   (1) arduino 16MHz
   (1) 38KHz IR receiver
   (1) breadboard
   (3) wires

IR - Arduino
 SIG - D2
 GND - GND
 VCC - VCC
*/

//definitions
#define IN_PIN 2
#define MAX_CAPTURE 584  // Line number 1

//globals
uint32_t now, start, capture[MAX_CAPTURE];
volatile bool flag_complete;
uint16_t i;    // Line number 2 uint8_t to uint16_t Key point of RAWBUF. uint8_t maximum range 255

//interrupt fires on ir event (rise/fall)
void IRInterrupt(void) {
 now = micros();
 capture[i++] = now - start;
 start = now;
 if (i >= MAX_CAPTURE) {
   detachInterrupt(0);
   flag_complete = true;
 }
}

void setup(void) {
 flag_complete = false;
 start = 0;
 now = 0;
 i = 0;
 Serial.begin(9600);
 attachInterrupt(0, IRInterrupt, CHANGE);
 Serial.println(“Ready to capture.”);
}

void loop(void) {
 while (1) {
   if (flag_complete) {
     for (i=0; i < MAX_CAPTURE; i++) {        
       Serial.println(capture[i]);
       //Serial.print(",");
       flag_complete = false;
     }
   }
 }
}






> uint16_t i; // Line number 2 uint8_t to uint16_t Key point of RAWBUF. uint8_t maximum range 255





> #define MAX_CAPTURE 584 // Line number 1, Value selected after hit and trial base experiments.



Hurray 8) here is the full IR sample values = 584 samples



> 3548,1640,492,1188,492,1192,492,348,492,344,492,348,492,1192,492,348,492,344,492,1192,492,1192,492,344,492,1192,492,348,492,348,492,1188,492,1192,492,348,492,1188,492,1192,492,348,488,348,492,1192,492,348,492,348,492,1188,492,348,492,348,492,348,488,348,492,348,492,348,492,348,492,348,488,348,492,348,492,348,492,348,492,348,492,344,492,348,492,348,492,348,492,348,492,344,492,348,492,1192,492,348,492,344,496,344,492,348,492,348,492,1188,492,1192,492,348,492,348,492,348,488,1192,492,1192,492,1188,492,1192,492,348,492,344,492,348,492,348,492,348,492,1188,492,1192,492,348,492,1188,492,1192,492,348,492,344,496,344,492,348,492,348,492,348,492,348,492,344,492,1192,492,348,492,348,492,344,492,348,492,348,492,348,492,348,492,344,492,348,492,348,492,348,492,348,492,344,496,344,492,348,492,348,492,348,492,348,492,344,492,348,492,348,492,348,492,348,492,344,492,348,492,348,492,348,492,348,492,344,492,348,492,348,492,348,492,348,492,348,492,344,492,348,492,348,492,348,492,348,492,344,492,348,492,348,492,348,492,348,492,344,492,348,492,348,492,348,492,348,492,344,496,344,492,348,492,348,492,348,492,348,492,344,492,348,492,348,492,1188,492,348,492,348,492,1192,492,348,492,1188,492,1192,492,12916,3544,1640,492,1188,492,1192,492,348,492,348,492,344,496,1188,492,348,492,348,492,1188,492,1192,492,348,492,1188,492,348,492,348,492,1188,492,1192,492,348,492,1188,492,1192,492,348,492,344,496,1188,492,348,492,348,492,1188,492,348,492,348,492,348,492,348,492,344,492,348,492,348,492,348,492,348,492,344,492,348,492,348,492,348,492,348,492,344,496,344,492,348,492,348,492,348,492,344,496,1188,492,348,492,348,492,344,496,344,492,348,492,1192,492,1188,492,348,492,348,492,348,492,1188,492,1192,492,1188,492,1192,492,348,492,348,492,344,492,348,492,348,492,1192,488,1192,492,348,492,1192,488,1192,492,348,492,348,492,344,496,344,496,344,492,348,492,348,492,348,492,1188,492,348,492,348,492,348,492,344,496,344,492,348,492,348,492,348,492,344,496,344,492,348,492,348,492,348,492,344,496,344,492,348,492,348,492,348,492,348,492,344,492,348,492,348,492,348,492,348,492,344,496,344,492,348,492,348,492,348,492,348,492,344,492,348,492,348,492,348,492,348,492,344,492,348,492,348,492,348,492,348,492,344,492,348,492,348,492,348,492,348,492,344,496,344,492,348,492,348,492,348,492,348,492,344,492,348,492,348,492,348,496,344,492,344,492,348,492,1192,492,348,492,344,492,1192,492,348,492,1188,492,1192,492,



what is happening in IR code expalned in attached excel file.

Second step finding the issue of IR remote library.



typedef struct {
 uint8_t recvpin;           // pin for IR data from detector
 uint8_t rcvstate;          // state machine
 uint8_t blinkflag;         // TRUE to enable blinking of pin 13 on IR processing
 unsigned int timer;     // state timer, counts 50uS ticks.
 unsigned int rawbuf[RAWBUF]; // raw data
 uint8_t rawlen;         // counter of entries in rawbuf
}
irparams_t;




Here it is


> uint8_t rawlen; maximum range 255



Solution:



typedef struct {
 uint8_t recvpin;           // pin for IR data from detector
 uint8_t rcvstate;          // state machine
 uint8_t blinkflag;         // TRUE to enable blinking of pin 13 on IR processing
 unsigned int timer;     // state timer, counts 50uS ticks.
 unsigned int rawbuf[RAWBUF]; // raw data
 uint16_t rawlen;         // counter of entries in rawbuf
}
irparams_t;




And hurray 292 samples



> 4718 3550 -1600 500 -1200 500 -1150 500 -350 550 -300 500 -350 500 -1150 500 -350 500 -350 500 -1200 450 -1200 500 -350 500 -1150 500 -350 550 -300 500 -1200 450 -1200 500 -350 500 -1200 450 -1200 500 -350 500 -350 500 -1150 500 -350 500 -350 500 -1150 500 -350 550 -300 500 -350 500 -350 450 -350 500 -350 500 -350 500 -350 450 -350 500 -350 500 -350 500 -350 450 -350 500 -350 500 -350 500 -350 500 -300 500 -350 500 -350 500 -350 500 -1150 500 -350 500 -350 500 -350 450 -350 500 -350 500 -1200 500 -1150 500 -350 500 -350 500 -350 450 -1200 550 -1150 500 -1150 500 -1200 500 -350 500 -350 500 -300 500 -350 500 -350 500 -1200 450 -1200 500 -350 500 -1150 500 -1200 500 -350 500 -350 500 -1150 500 -1200 500 -350 500 -300 500 -350 500 -350 500 -1150 500 -350 550 -300 500 -350 500 -350 450 -350 500 -350 500 -350 500 -350 450 -350 500 -350 500 -350 500 -350 450 -350 500 -350 500 -350 500 -350 500 -300 500 -350 500 -350 500 -350 500 -350 450 -350 500 -350 500 -350 500 -350 450 -350 500 -350 500 -350 500 -350 450 -350 500 -350 500 -350 500 -350 500 -300 500 -350 500 -350 500 -350 500 -350 500 -1150 500 -350 500 -350 450 -350 500 -350 500 -350 500 -350 500 -300 500 -350 500 -350 500 -350 500 -350 450 -350 500 -350 500 -350 500 -350 450 -350 500 -350 500 -350 500 -1150 500 -350 500 -1200 500 -350 500 -1150 500 -1200 500 -1150 500 -1200 500



why 292 not 584?
reason is, same IR code sent twice with space of 12ms b/w them.

Now it is clear and it will take 10 min to write the code of sendMit of both of you.

Goodluck.

Edit: If you get the raw code after the above modification and send it in raw it will work.

@pndtkd… you have long code and you have to send your code twice with specific space bwteen them.
i.e.xxxxxspacexxxxx.Follow teh above instructions you will com to know. If you have problem with this stuff then post it here.
There are a lot of techniques for decoding IR remote
2 method are discussed here
1: Gnuplot method
2:IR analyser
3:http://ucexperiment.wordpress.com/2012/02/14/reverse-engineering-an-aim-ir-beacon-transmitter/(i prefer you to follow this)
4: Interface your Sound card with the Receiver
5:Oscilloscope
You can decode with any technique that is easy for you

@arslankhan... I don't receive nothing with "your" decode sketch; you receive: C4D364800024C0F0000000000CDE

BUT, i find this: https://github.com/erix/arduino/blob/master/ir_analyzer/ir_analyzer.ino my results are:

Analyze IR Remote 23CB260100005806166300000000100000FC 23C9260100005806166300000000100000FC 23CB2601002058061663000000001000001C 23CB2601002058061663000000001000001C

what do you think about? why are they different (before, the first time, my output was:....Address: C4D3 Value: 64800004 (48 bits)..... ) Now i do't have C4D3......but 23CB...... Finally, how can i use the sketch to sende codes?

pndtkd:
@arslankhan… I don’t receive nothing with “your” decode sketch; you receive: C4D364800024C0F0000000000CDE

It may be different as different models of Mitsubishi. but your result, I think something wrong with you.

what do you think about?

I think its Wrong.
run this Program and come with the output.

/*
  IR Capture
  Copyright 2012, all rights reserved.
  James M. Eli
  1/14/2012
 
  project parts:
    (1) arduino 16MHz
    (1) 38KHz IR receiver
    (1) breadboard
    (3) wires
 
  IR - Arduino
  SIG - D2
  GND - GND
  VCC - VCC
*/

//definitions
#define IN_PIN 2
#define MAX_CAPTURE 584  // Line number 1
 
//globals
uint32_t now, start, capture[MAX_CAPTURE];
volatile bool flag_complete;
uint16_t i;    // Line number 2 uint8_t to uint16_t Key point of RAWBUF. uint8_t maximum range 255
 
//interrupt fires on ir event (rise/fall)
void IRInterrupt(void) {
  now = micros();
  capture[i++] = now - start;
  start = now;
  if (i >= MAX_CAPTURE) {
    detachInterrupt(0);
    flag_complete = true;
  }
}
 
void setup(void) {
  flag_complete = false;
  start = 0;
  now = 0;
  i = 0;
  Serial.begin(9600);
  attachInterrupt(0, IRInterrupt, CHANGE);
  Serial.println("Ready to capture.");
}
 
void loop(void) {
  while (1) {
    if (flag_complete) {
      for (i=0; i < MAX_CAPTURE; i++) {        
        Serial.println(capture[i]);
        //Serial.print(",");
        flag_complete = false;
      }
    }
  }
}

There is a problem in this sketch....in the serial monitor i don't see "Ready to capture"... Can you try now with this code if it works?

tnx

Francesco

OK....i change #define MAX_CAPTURE 425 and your code works.... this is my results: now? Ready to capture. 2053108 3520 1648 460 1264 460 1264 468 404 460 408 460 400 464 1264 460 404 488 384 460 1264 464 1252 512 360 484 1240 512 360 484 388 460 1260 468 1256 464 404 460 1260 512 1220 460 404 488 388 464 1260 464 404 460 416 460 1260 508 360 512 360 464 408 464 404 508 364 460 408 460 400 464 416 484 384 464 404 464 400 464 400 464 408 460 400 464 404 484 384 484 384 488 384 484 384 508 364 460 1264 480 388 464 396 484 388 460 408 512 356 464 1264 512 1220 460 408 480 1244 488 388 508 360 460 1264 464 1256 488 384 512 356 468 400 508 364 460 408 460 408 484 1244 460 1268 508 364 460 1264 460 408 460 400 468 404 484 1244 464 1264 508 356 468 400 464 400 464 1260 508 1216 468 404 460 404 464 404 504 360 488 388 460 404 464 400 508 364 464 404 512 356 484 384 512 360 508 364 484 384 480 388 464 404 464 404 460 408 460 404 464 404 460 408 460 408 460 404 468 400 460 408 460 404 508 360 464 404 464 404 480 388 468 400 508 360 508 360 464 400 468 396 464 408 460 404 508 1220 512 364 484 380 484 384 464 404 484 384 512 364 464 416 468 400 480 392 464 400 464 404 460 416 508 364 460 404 464 400 460 408 460 404 464 400 464 408 480 388 484 380 512 1220 508 1216 464 1256 464 404 464 400 464 404 508 16980 3612 1704 480 1244 480 1244 464 408 460 408 484 380 484 1240 468 404 460 404 464 1260 464 1260 484 388 460 1264 488 384 468 400 460 1264 464 1260 512 360 508 1216 468 1260 464 400 508 360 464 1260 468 400 460 408 460 1260 492 380 464 400 508 360 508 360 512 360 460 404 468 404 488 384 464 400 488 388 464 404 464 404 460 400 508 364 468 400 464 408 508 356 488 380 516 360 460 404 464 1264 464 408 508 356 484 388 468 400 460 408 460 1264 464 1260 468 400 488 1232 468 404 460 408 484 1236 464 1260 468 400 484 388 460 408 464 400 464 404 460 404

@arslankhan
Now i have used this code to take HEX (your code):
MAX_CAPTURE 584…I don’t see nothing with this code.
MAX_CAPTURE 425…i can see Ready to capture and C
MAX_CAPTURE 400…i see my code(hope) C4D3648000041A6068C60000000008000038 :smiley:

but, i don’t know why, sometimes it changes…

What do you think now?

#define IN_PIN 2
#define MAX_CAPTURE 400

//globals
uint32_t now, start, capture[MAX_CAPTURE];
volatile bool flag_complete;
uint16_t i;
int first,second,diff,total;
int counter=0;
int bits=0;
unsigned long data=0;
unsigned long data1=0;
unsigned long data2=0;
unsigned long data3=0;
unsigned long data4=0;
unsigned long data5=0;

//interrupt fires on ir event (rise/fall)
void IRInterrupt(void) {
  now = micros();
  capture[i++] = now - start;
  start = now;
  if (i >= MAX_CAPTURE) {
    detachInterrupt(0);
    flag_complete = true;
  }
}

void setup(void) {
  flag_complete = false;
  start = 0;
  now = 0;
  i = 0;
  Serial.begin(9600);
  attachInterrupt(0, IRInterrupt, CHANGE);
  Serial.println("Ready to capture.");
}

void loop(void) {
  while (1) {
    if (flag_complete) {
      for (i=0; i < MAX_CAPTURE; i++) {   
        counter++;  
        first=capture[i];
        second=capture[i+1];

        if(first>12900 && first<13700){
          break;
        }
  if(counter<2)
  {

          total=first+second;

          if(total<900 && total>700)
          {
            data <<= 1;
          }
          if(total>1600 && total<1800)
          {
            data = (data << 1) | 1;  
          }
          bits++;
  }
  else
  {
          counter=0;
  }
        if(bits==34)
        {
          data1=data;
        }
        else if(bits==66)
        {
          data2=data;
        }
        else if(bits==98)
        {
          data3=data;
        }
        else if(bits==130)
        {
          data5=data;
        }
        else if(bits==146)
        {
          data5=data;
          Serial.print(data1,HEX);
          Serial.print("000");
          Serial.print(data2,HEX);
          Serial.print(data3,HEX);
          Serial.print(data4,HEX);
          Serial.print("0000");
          Serial.println(data5,HEX);
        }

        flag_complete = false;
      }
    }
  }
}

i think im near to solution(hope)…i used gnuplot and i think that there are some problems (overflow)…
infact reading mark/space chart like you, i obtain a wrong number BUT, IF I ADD 6 ZEROS TO THIS NUMBER i obtain the same number i said before: C4D3648000041A6068C60000000008000038 …probably because of the overflow that was corrected in your code…

now i only have to send it…but i don’t know how yet! :roll_eyes:

Code cracked...Mitsubishi Kirigamine works correctly with:

0xC4D36480,0x00041A60,0x68C60000,0x00000800,0x00380000

thank you all especially to arslankhan

Have just read this post with great interest.

For anyone interested in decoding IR protocols - we have just launched a Crowdfunding project on IndieGoGo for AnalysIR - IR Decoder & Analyzer GUI (Arduino & Raspberry Pi). Currently we support 17 IR protocols and are looking for more to add as part of the project. Suggestions Welcome!

Currently we don't decode AC remotes (but do record & display them graphically), but would love to give it a try. We will add this to the list of IR protocols to be added to AnalysIR. The people who back our project get to vote on which protocols to add. The other issue we have is that there isnt much need for AC in Dublin so its hard to get a remote to play with. However, we should be able to do something with the raw timings on this thread.

You can find out more about the project on http://igg.me/at/AnalysIR/x/3752156 or Screenshot via www.AnalysIR.com or Meet us at DublinMakerFaire on Jul 27th

tnx

pndtkd: Code cracked...Mitsubishi Kirigamine works correctly with:

0xC4D36480,0x00041A60,0x68C60000,0x00000800,0x00380000

thank you all especially to arslankhan

What's the code you used to send that?

Hello everyone,
this is my very first post here, given that i’m at a beginner level with Arduino.
I’m trying to decode IR signals coming from an universal AC remote control. My AC is a Schneider Clima and i don’t know its protocol, even though the signal set on the RC says it should be similar to a Mitsubishi model.
Anyway, i tried to decode the IR signals with the following code:

#define IN_PIN 2
#define MAX_CAPTURE 400

//globals
uint32_t now, start, capture[MAX_CAPTURE];
volatile bool flag_complete;
uint16_t i;
int first,second,diff,total;
int counter=0;
int bits=0;
unsigned long data=0;
unsigned long data1=0;
unsigned long data2=0;
unsigned long data3=0;
unsigned long data4=0;
unsigned long data5=0;

//interrupt fires on ir event (rise/fall)
void IRInterrupt(void) {
  now = micros();
  capture[i++] = now - start;
  start = now;
  if (i >= MAX_CAPTURE) {
    detachInterrupt(0);
    flag_complete = true;
  }
}

void setup(void) {
  flag_complete = false;
  start = 0;
  now = 0;
  i = 0;
  Serial.begin(9600);
  attachInterrupt(0, IRInterrupt, CHANGE);
  Serial.println("Ready to capture.");
}

void loop(void) {
  while (1) {
    if (flag_complete) {
      for (i=0; i < MAX_CAPTURE; i++) {   
        counter++;  
        first=capture[i];
        second=capture[i+1];

        if(first>12900 && first<13700){
          break;
        }
  if(counter<2)
  {

          total=first+second;

          if(total<900 && total>700)
          {
            data <<= 1;
          }
          if(total>1600 && total<1800)
          {
            data = (data << 1) | 1;  
          }
          bits++;
  }
  else
  {
          counter=0;
  }
        if(bits==34)
        {
          data1=data;
        }
        else if(bits==66)
        {
          data2=data;
        }
        else if(bits==98)
        {
          data3=data;
        }
        else if(bits==130)
        {
          data5=data;
        }
        else if(bits==146)
        {
          data5=data;
          Serial.print(data1,HEX);
          Serial.print("000");
          Serial.print(data2,HEX);
          Serial.print(data3,HEX);
          Serial.print(data4,HEX);
          Serial.print("0000");
          Serial.println(data5,HEX);
        }

        flag_complete = false;
      }
    }
  }
}

The code is the same as the one posted by pndtkd and similar to the one posted by arslankhan.
When i push the On/Off button i receive following codes:
3134D9200009203437000000000001C4D3648
3134D9200009203437000000000001C4D3648

189A6C900004901A1B80000000000E269B24
189A6C900004901A1B80000000000E269B24

00003134D929203000000
00003134D929203000000

189A6C000900004901A1B8000000007134D
189A6C000900004901A1B8000000007134D

C4D3000B2400024481A1E0000000389A
C4D3000B2400024481A1E0000000389A

6269B240001240686E00000000001C4D364
6269B240001240686E00000000001C4D364

3134D92000920343700000000007134D9
3134D92000920343700000000007134D9

C4D36480002480DDC0000000000E269B2
C4D36480002480DDC0000000000E269B2

3134D9200092034370000000000E269B2
3134D9200092034370000000000E269B2

C4D36400080002480D0DC0000000001C4D36
C4D36400080002480D0DC0000000001C4D36

I tried to send all of them to my AC, but no one seems to be ok.
First thing i notice, every time i push the On/Off button, Arduino gives me a different code. Who knows why?
Who can me explain a safe method for the IR signals decoding?
Thanks in advance!

Enzo

A quick glance at the first 2 sets of (2) codes you provided, looks like you [u]may[/u] have the bits shifted one place to the left (or right).

So look in your code to see, if there is a cause.

Make sure you start decoding from a known state each time.

Sorry, dont have enough time now to debug it more for you.

AnalysIR:
A quick glance at the first 2 sets of (2) codes you provided, looks like you may have the bits shifted one place to the left (or right).

So look in your code to see, if there is a cause.

Make sure you start decoding from a known state each time.

Sorry, dont have enough time now to debug it more for you.

Thanks so much for answering.

The code i used is the following:

#define IN_PIN 2
#define MAX_CAPTURE 400

//globals
uint32_t now, start, capture[MAX_CAPTURE];
volatile bool flag_complete;
uint16_t i;
int first,second,diff,total;
int counter=0;
int bits=0;
unsigned long data=0;
unsigned long data1=0;
unsigned long data2=0;
unsigned long data3=0;
unsigned long data4=0;
unsigned long data5=0;

//interrupt fires on ir event (rise/fall)
void IRInterrupt(void) {
  now = micros();
  capture[i++] = now - start;
  start = now;
  if (i >= MAX_CAPTURE) {
    detachInterrupt(0);
    flag_complete = true;
  }
}

void setup(void) {
  flag_complete = false;
  start = 0;
  now = 0;
  i = 0;
  Serial.begin(9600);
  attachInterrupt(0, IRInterrupt, CHANGE);
  Serial.println("Ready to capture.");
}

void loop(void) {
  while (1) {
    if (flag_complete) {
      for (i=0; i < MAX_CAPTURE; i++) {   
        counter++;  
        first=capture[i];
        second=capture[i+1];

        if(first>12900 && first<13700){
          break;
        }
  if(counter<2)
  {

          total=first+second;

          if(total<900 && total>700)
          {
            data <<= 1;
          }
          if(total>1600 && total<1800)
          {
            data = (data << 1) | 1;  
          }
          bits++;
  }
  else
  {
          counter=0;
  }
        if(bits==34)
        {
          data1=data;
        }
        else if(bits==66)
        {
          data2=data;
        }
        else if(bits==98)
        {
          data3=data;
        }
        else if(bits==130)
        {
          data5=data;
        }
        else if(bits==146)
        {
          data5=data;
          Serial.print(data1,HEX);
          Serial.print("000");
          Serial.print(data2,HEX);
          Serial.print(data3,HEX);
          Serial.print(data4,HEX);
          Serial.print("0000");
          Serial.println(data5,HEX);
        }

        flag_complete = false;
      }
    }
  }
}

I’d really appreciate if you could debug it. Of course, take your time =)

Hi,
I have an issue. I have Mitsubishi Airco Unit. Using this code:

I captured my remote command to turn on my Unit.
I press Power On Command from my remote and I got this code:
C4D3648000041A6068C60000000008000038

From this code i obtained 5 pieces:
0xC4D36480
0x00041A60
0x68C60000
0x00000800
0x0038

i added 4 zeros to the last one and became 0x00380000

Then i try to use code from this post

to send command. I modified the library, and use this schetch to send:

[code]#include <IRremote.h>
#include <IRremoteInt.h>

IRsend irsend;

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

void loop() {
    for(int i=0;i<2;i++)
    {
        irsend.sendMitsubishi(0xC4D36480,0x00041260,0xA1E21000,0x00001000,0x00EB0000);
    }
        delay(5000);
}

[/code]

but does not work, led blink so not an hardware issue.
Someone can help me?
Thanks

Marco

Hi all, if I send to my Airco Unit the codes from @pndtkd, it works. Command is:

irsend.sendMitsubishi(0xC4D36480,0x00041A60,0x68C60000,0x00000800,0x00380000);

My airco Turn On. So Sending routine is working fine. My issue now is capture routine. Each time I capture a Turn On code, I get differents, for example:

Ready to capture.
C4EDA400008258C063CE4000000800047
C4EDA400008258C063CE4000000800047
Ready to capture.
1AD6C90000480042B0B033DC8000000800047
1AD6C90000480042B0B033DC8000000800047
Ready to capture.
18B5B240000800089308050F3A000000200047
18B5B240000800089308050F3A000000200047
Ready to capture.
18B4D9200001056080C7B88000000800047
18B4D9200001056080C7B88000000800047
Ready to capture.
32D6D4000020A60C029E72000000400047
32D6D4000020A60C029E72000000400047

I capture my codes using this: http://forum.arduino.cc/index.php?topic=151199.msg1274145#msg1274145

What I miss?

Thanks

Hi All,

This is my first time in this forum. Hope that someone can help with some questions.

I am also trying to do the same thing. Turn on and off my Mitsubishi air conditioner. I have 3 different models. 1 at home and 2 in the the office.

My first attempt was to try to make the one at home work. I used the code from here
https://github.com/adafruit/Raw-IR-decoder-for-Arduino
And I was successful. I was able to turn on and turn off the aircon. No real issue. So I thought I got it figured out.

But when I try it in the office, it does not work!!

The air con in the office were same brand but different models. So I read the IR code again and then resend it out like in my house, but it does not work. Then I stumbled on this thread. Hopefully someone can help me.

I have tried reading the code using the same code that pndtkd and arslankhan used but it does not seem to work.
Even sending in RAW code does not work either.

I have seen alot of suggestions so I would like to clarify some doubts.

  1. Do we need to add in the fixTimer() code? Or does the default works?
  2. When sending the code out, is it necessary to send it 2 times?

Hi guys… i have a ariston AC.
i have tried this sketch

#define IN_PIN 2
#define MAX_CAPTURE 400

//globals
uint32_t now, start, capture[MAX_CAPTURE];
volatile bool flag_complete;
uint16_t i;
int first,second,diff,total;
int counter=0;
int bits=0;
unsigned long data=0;
unsigned long data1=0;
unsigned long data2=0;
unsigned long data3=0;
unsigned long data4=0;
unsigned long data5=0;

//interrupt fires on ir event (rise/fall)
void IRInterrupt(void) {
  now = micros();
  capture[i++] = now - start;
  start = now;
  if (i >= MAX_CAPTURE) {
    detachInterrupt(0);
    flag_complete = true;
  }
}

void setup(void) {
  flag_complete = false;
  start = 0;
  now = 0;
  i = 0;
  Serial.begin(9600);
  attachInterrupt(0, IRInterrupt, CHANGE);
  Serial.println("Ready to capture.");
}

void loop(void) {
  while (1) {
    if (flag_complete) {
      for (i=0; i < MAX_CAPTURE; i++) {   
        counter++;  
        first=capture[i];
        second=capture[i+1];

        if(first>12900 && first<13700){
          break;
        }
  if(counter<2)
  {

          total=first+second;

          if(total<900 && total>700)
          {
            data <<= 1;
          }
          if(total>1600 && total<1800)
          {
            data = (data << 1) | 1;  
          }
          bits++;
  }
  else
  {
          counter=0;
  }
        if(bits==34)
        {
          data1=data;
        }
        else if(bits==66)
        {
          data2=data;
        }
        else if(bits==98)
        {
          data3=data;
        }
        else if(bits==130)
        {
          data5=data;
        }
        else if(bits==146)
        {
          data5=data;
          Serial.print(data1,HEX);
          Serial.print("000");
          Serial.print(data2,HEX);
          Serial.print(data3,HEX);
          Serial.print(data4,HEX);
          Serial.print("0000");
          Serial.println(data5,HEX);
        }

        flag_complete = false;
      }
    }
  }
}

but the output is:

Ready to capture.
000000000000
000000000000

and i have tried another sketch:

#include <avr/interrupt.h>
#include <avr/io.h>

#define TIMER_RESET  TCNT1 = 0
#define SAMPLE_SIZE  232

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

void setup() {
  Serial.begin(9600);
  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 my output is:

Analyze IR Remote
Waiting...
Bit stream detected!
0	0
4492	0
4492	1
8920	1
8920	0
9516	0
9516	1
11120	1
11120	0
11708	0
11708	1
12220	1
12220	0
12812	0
12812	1
14416	1
14416	0
15004	0
15004	1
16612	1
16612	0
17208	0
17208	1
17712	1
17712	0
18312	0
18312	1
18812	1
18812	0
19404	0
19404	1
21008	1
21008	0
21608	0
21608	1
22108	1
22108	0
22700	0
22700	1
23208	1
23208	0
23800	0
23800	1
25408	1
25408	0
25996	0
25996	1
26504	1
26504	0
27100	0
27100	1
27604	1
27604	0
28200	0
28200	1
29800	1
29800	0
30396	0
30396	1
32004	1
32004	0
32600	0
32600	1
33104	1
33104	0
33692	0
33692	1
35300	1
35300	0
35896	0
35896	1
36400	1
36400	0
36988	0
36988	1
37496	1
37496	0
38088	0
38088	1
39696	1
39696	0
40292	0
40292	1
41892	1
41892	0
42488	0
42488	1
44092	1
44092	0
44680	0
44680	1
46288	1
46288	0
46884	0
46884	1
48484	1
48484	0
49080	0
49080	1
50688	1
50688	0
51272	0
51272	1
52884	1
52884	0
53480	0
53480	1
55080	1
55080	0
55672	0
55672	1
56184	1
56184	0
56776	0
56776	1
57280	1
57280	0
57876	0
57876	1
58380	1
58380	0
58968	0
58968	1
59480	1
59480	0
60068	0
60068	1
60580	1
60580	0
61172	0
61172	1
61676	1
61676	0
62272	0
62272	1
63876	1
63876	0
64468	0
64468	1
64972	1
64972	0
65568	0
65568	1
67172	1
67172	0
67768	0
67768	1
69368	1
69368	0
69960	0
69960	1
71568	1
71568	0
72160	0
72160	1
73764	1
73764	0
74360	0
74360	1
74864	1
74864	0
75456	0
75456	1
75964	1
75964	0
76560	0
76560	1
77064	1
77064	0
77652	0
77652	1
79260	1
79260	0
79860	0
79860	1
80360	1
80360	0
80948	0
80948	1
81456	1
81456	0
82052	0
82052	1
82556	1
82556	0
83156	0
83156	1
83656	1
83656	0
84244	0
84244	1
85856	1
85856	0
86452	0
86452	1
88052	1
88052	0
88644	0
88644	1
93916	1
93916	0
98432	0
98432	1
102864	1
102864	0
103456	0
103456	1
105064	1
105064	0
105652	0
105652	1
106164	1
106164	0
106752	0
106752	1
108356	1
108356	0
108960	0
108960	1
110560	1
110560	0
111152	0
111152	1
111660	1
111660	0
112256	0
112256	1
112756	1
112756	0
113348	0
113348	1
114956	1
114956	0
115548	0
115548	1
116052	1
116052	0
116640	0
116640	1
117152	1
117152	0
117744	0
117744	1
119348	1
119348	0
119948	0
119948	1
120448	1
120448	0
121040	0
121040	1
121548	1
121548	0
122144	0
122144	1
123748	1
123748	0
124336	0
124336	1
125944	1
125944	0
126540	0
126540	1
127044	1
127044	0
127632	0
127632	1
129240	1
129240	0
129836	0
129836	1
130340	1
130340	0
130940	0
130940	1
131440	1
131440	0
132028	0
132028	1
133640	1
133640	0
134236	0
134236	1
135836	1
135836	0
136428	0
136428	1
138040	1
138040	0
138624	0
138624	1
140232	1
140232	0
140828	0
140828	1
142432	1
142432	0
143020	0
143020	1
144628	1
144628	0
145228	0
145228	1
146824	1
146824	0
147420	0
147420	1
149024	1
149024	0
149612	0
149612	1
150124	1
150124	0
150716	0
150716	1
151220	1
151220	0
151820	0
151820	1
152320	1
152320	0
152920	0
152920	1
153420	1
153420	0
154012	0
154012	1
154520	1
154520	0
155112	0
155112	1
155620	1
155620	0
156216	0
156216	1
157816	1
157816	0
158408	0
158408	1
158916	1
158916	0
159512	0
159512	1
161112	1
161112	0
161708	0
161708	1
163316	1
163316	0
163900	0
163900	1
165512	1
165512	0
166108	0
166108	1
167708	1
167708	0
168300	0
168300	1
168808	1
168808	0
169404	0
169404	1
169908	1
169908	0
170504	0
170504	1
171008	1
171008	0
171596	0
171596	1
173204	1
173204	0
173804	0
173804	1
174304	1
174304	0
174892	0
174892	1
175404	1
175404	0
175992	0
175992	1
176500	1
176500	0
177096	0
177096	1
177600	1
177600	0
178200	0
178200	1
179800	1
179800	0
180392	0
180392	1
181996	1
181996	0
182588	0
182588	1
50552	1
50552	0
55052	0
55052	1
59480	1
59480	0
60076	0
60076	1
61676	1
61676	0
62272	0
62272	1
62776	1
62776	0
63372	0
63372	1
64972	1
64972	0
65568	0
65568	1
67172	1
67172	0
67760	0
67760	1
68268	1
68268	0
68864	0
68864	1
69368	1
69368	0
69964	0
69964	1
71568	1
71568	0
72160	0
72160	1
72668	1
72668	0
73260	0
73260	1
73764	1
73764	0
74364	0
74364	1
75964	1
75964	0
76556	0
76556	1
77064	1
77064	0
77660	0
77660	1
78160	1
78160	0
78752	0
78752	1
80360	1
80360	0
80952	0
80952	1
82560	1
82560	0
83152	0
83152	1
Bit stream end!
Waiting...

This is a photo with gnuplot…

can anyone help me please? :frowning:

I suggest you try the IRremote (or IRLib) library, as it has most of the work done already.

I presume you are trying to decode the IR signals?