IR signal recording and replication

Hi,

I want to read out an IR signal and save the code for later usage. The IR code is unknown in all sense, the equipment with the IR signal is something mainly used in the industy and not in household appliances.

Is there a way to make the script so that making the copy of the IR signal will be easy? Preferably so that coding a standalone transmitter circuit later on will be easy?

I will have to teach a person with no experience in arduino how to read out the code and then test it before handing it over to me. I on the other hand will not be able to test it at all.

Well i got a setup that seems to work now.

Will this work regardless of library etc.? I am guessing i only have one unknown signal to copy.

I am having a challenge with the replication of the signal.

I tested the code with a remote and then read it in again to see what i got.

first read was:

// ON, OFF (in 10's of microseconds)
  498, 432,
  90, 140,
  88, 144,
  88, 142,
  90, 24,
  82, 36,
  66, 50,
  64, 50,
  66, 50,
  64, 168,
  62, 168,
  64, 166,
  62, 54,
  62, 54,
  60, 56,
  58, 58,
  56, 58,
  58, 58,
  56, 174,
  58, 58,
  56, 58,
  58, 58,
  58, 58,
  58, 56,
  58, 58,
  56, 174,
  58, 58,
  56, 174,
  58, 172,
  58, 174,
  58, 172,
  58, 172,
  58, 174,
  56, 4826,
  466, 464,
  58, 172,
  58, 172,
  58, 174,
  56, 58,
  58, 58,
  56, 60,
  56, 58,
  58, 56,
  58, 174,
  58, 172,
  58, 174,
  56, 58,
  58, 58,
  56, 58,
  58, 58,
  58, 56,
  58, 58,
  58, 172,
  58, 58,
  56, 60,
  56, 58,
  58, 58,
  56, 60,
  56, 58,
  58, 172,
  58, 58,
  58, 172,
  58, 174,
  56, 174,
  56, 174,
  58, 172,
  58, 174,
  56, 0};

When played this code and tried to read it again i got a totally different read..

What is the problem here?

I think the problem is that you didn't show your code, you didn't provide info on the circuit you use, the sensors you use, the IR LED you use, and just about everything else.

That failing, a link to a reliably working and affordable crystal ball would be great.

Thinkerion:
Hi,

I want to read out an IR signal and save the code for later usage. The IR code is unknown in all sense, the equipment with the IR signal is something mainly used in the industy and not in household appliances.

Is there a way to make the script so that making the copy of the IR signal will be easy? Preferably so that coding a standalone transmitter circuit later on will be easy?

I will have to teach a person with no experience in arduino how to read out the code and then test it before handing it over to me. I on the other hand will not be able to test it at all.

Well i have actually posted a link to the setup i am using.
Here it is again: Clone Infrared Signals with Arduino - Arduino Project Hub

Currently i am testing a range of IR diodes to see if it will help.
Only difference is that i am using an NPN to boost the IR power a litle.

I will come back with further info when i have it.

Decoding Code: (for some odd reason this read now fails, even though it worked earlier.)

/* Raw IR decoder sketch!
This sketch/program uses the Arduno and a PNA4602 to
decode IR received. This can be used to make a IR receiver
(by looking for a particular code)
or transmitter (by pulsing an IR LED at ~38KHz for the
durations detected
Code is public domain, check out www.ladyada.net and adafruit.com
for more tutorials!
*/

// We need to use the 'raw' pin reading methods
// because timing is very important here and the digitalRead()
// procedure is slower!
//uint8_t IRpin = 2;
// Digital pin #2 is the same as Pin D2 see
// http://arduino.cc/en/Hacking/PinMapping168 for the 'raw' pin mapping
#define IRpin_PIN PIND
#define IRpin 2
// for MEGA use these!
//#define IRpin_PIN PINE
//#define IRpin 4

// the maximum pulse we'll listen for - 65 milliseconds is a long time
#define MAXPULSE 65000

// what our timing resolution should be, larger is better
// as its more 'precise' - but too large and you wont get
// accurate timing
#define RESOLUTION 20

// we will store up to 100 pulse pairs (this is -a lot-)
uint16_t pulses[100][2]; // pair is high and low pulse
uint8_t currentpulse = 0; // index for pulses we're storing

void setup(void) {
  Serial.begin(9600);
  Serial.println("Ready to decode IR!");
}

void loop(void) {
  uint16_t highpulse, lowpulse; // temporary storage timing
  highpulse = lowpulse = 0; // start out with no pulse length
  
  
// while (digitalRead(IRpin)) { // this is too slow!
    while (IRpin_PIN & (1 << IRpin)) {
     // pin is still HIGH

     // count off another few microseconds
     highpulse++;
     delayMicroseconds(RESOLUTION);

     // If the pulse is too long, we 'timed out' - either nothing
     // was received or the code is finished, so print what
     // we've grabbed so far, and then reset
     if ((highpulse >= MAXPULSE) && (currentpulse != 0)) {
       printpulses();
       currentpulse=0;
       return;
     }
  }
  // we didn't time out so lets stash the reading
  pulses[currentpulse][0] = highpulse;
  
  // same as above
  while (! (IRpin_PIN & _BV(IRpin))) {
     // pin is still LOW
     lowpulse++;
     delayMicroseconds(RESOLUTION);
     if ((lowpulse >= MAXPULSE) && (currentpulse != 0)) {
       printpulses();
       currentpulse=0;
       return;
     }
  }
  pulses[currentpulse][1] = lowpulse;

  // we read one high-low pulse successfully, continue!
  currentpulse++;
}

void printpulses(void) {
  Serial.println("\n\r\n\rReceived: \n\rOFF \tON");
  for (uint8_t i = 0; i < currentpulse; i++) {
    Serial.print(pulses[i][0] * RESOLUTION, DEC);
    Serial.print(" usec, ");
    Serial.print(pulses[i][1] * RESOLUTION, DEC);
    Serial.println(" usec");
  }
 
  // print it in a 'array' format
  Serial.println("int IRsignal[] = {");
  Serial.println("// ON, OFF (in 10's of microseconds)");
  for (uint8_t i = 0; i < currentpulse-1; i++) {
    Serial.print("\t"); // tab
    Serial.print(pulses[i][1] * RESOLUTION / 10, DEC);
    Serial.print(", ");
    Serial.print(pulses[i+1][0] * RESOLUTION / 10, DEC);
    Serial.println(",");
  }
  Serial.print("\t"); // tab
  Serial.print(pulses[currentpulse-1][1] * RESOLUTION / 10, DEC);
  Serial.print(", 0};");
}

IR play code. I changed the trigger to a button.

// This program allows an Arduino to power on/off a Duraflame heater using infrared
//
// Usage: hook up an IR led with Annode on pin 13.  Then send serial data "POWER"
// to the arduino.  It should flash the LED code.
//
// By Rick Osgood with code borrowed from adafruit.com
//

#define IRledPin 13
#define NumIRsignals 68
const int Button = 6;

int buttonstate = 0;
      
// This is the code I determined works for my Duraflame heater
int IRsignal[] = {
// ON, OFF (in 10's of microseconds)
  498, 432,
  90, 140,
  88, 144,
  88, 142,
  90, 24,
  82, 36,
  66, 50,
  64, 50,
  66, 50,
  64, 168,
  62, 168,
  64, 166,
  62, 54,
  62, 54,
  60, 56,
  58, 58,
  56, 58,
  58, 58,
  56, 174,
  58, 58,
  56, 58,
  58, 58,
  58, 58,
  58, 56,
  58, 58,
  56, 174,
  58, 58,
  56, 174,
  58, 172,
  58, 174,
  58, 172,
  58, 172,
  58, 174,
  56, 4826,
  466, 464,
  58, 172,
  58, 172,
  58, 174,
  56, 58,
  58, 58,
  56, 60,
  56, 58,
  58, 56,
  58, 174,
  58, 172,
  58, 174,
  56, 58,
  58, 58,
  56, 58,
  58, 58,
  58, 56,
  58, 58,
  58, 172,
  58, 58,
  56, 60,
  56, 58,
  58, 58,
  56, 60,
  56, 58,
  58, 172,
  58, 58,
  58, 172,
  58, 174,
  56, 174,
  56, 174,
  58, 172,
  58, 174,
  56, 0};

void setup(void) {
  pinMode(Button, INPUT);
  digitalWrite(IRledPin, LOW);   //Make sure LED starts "off"
  Serial.begin(9600);            //Initialize Serial port
}

void loop() {
  char data[6];
  int index = 0;

  buttonstate = digitalRead(Button);

 //  delay(1000);  //Serial input seems to need some kind of short delay or the data gets screwed up.

//  while (Serial.available() > 0) {            //Loop if there data on the serial line
//    if (index < 5) {                          //Make sure we don't overflow
//      data[index] = Serial.read();            //Load a character into the string
//      index++;                                //Increment the index to get the next character
//    }
//  }
  
//  data[5]='\0';  //Null terminate the string
  
  if (buttonstate == HIGH){                //If the Arduino receives the POWER signal...
    Serial.println("SENDING SIGNAL!");
    for (int i = 0; i < NumIRsignals; i+=2) {         //Loop through all of the IR timings
      pulseIR(IRsignal[i]*10);              //Flash IR LED at 38khz for the right amount of time
      delayMicroseconds(IRsignal[i+1]*10);  //Then turn it off for the right amount of time
    }
  }                                         //Otherwise do nothing!
}

// This function allows us to PWM the IR LED at about 38khz for the sensor
// Borrowed from Adafruit!
void pulseIR(long microsecs) {
  // we'll count down from the number of microseconds we are told to wait
 
  cli();  // this turns off any background interrupts
 
  while (microsecs > 0) {
    // 38 kHz is about 13 microseconds high and 13 microseconds low
   digitalWrite(IRledPin, HIGH);  // this takes about 3 microseconds to happen
   delayMicroseconds(10);         // hang out for 10 microseconds, you can also change this to 9 if its not working
   digitalWrite(IRledPin, LOW);   // this also takes about 3 microseconds
   delayMicroseconds(10);         // hang out for 10 microseconds, you can also change this to 9 if its not working
 
   // so 26 microseconds altogether
   microsecs -= 26;
  }
 
  sei();  // this turns them back on
}