sending IR codes direct to IR receiver pin

Hi All,

I am trying to control a video camera using an arduino. The buttons are attached to a thin membrane going to a small zif socket and I've had no luck attaching the mini pro to them. My current idea is to use the IR in to control the device. I have downloaded the codes from the remote control using IRremote library and have followed this thread Bypassing IR control on HDMI switcher - Project Guidance - Arduino Forum for inspiration but the camera is not responding to any of my commands.

The code I am currently using is:

#include <IRremote.h>

// pulse parameters in usec
#define NEC_HDR_MARK  9000
#define NEC_HDR_SPACE 4500
#define NEC_BIT_MARK  560
#define NEC_ONE_SPACE 1600
#define NEC_ZERO_SPACE  560
#define NEC_RPT_SPACE 2250

#define TOPBIT 0x80000000

const int OutputPin = 11;

IRsend irsend;

void setup(){
  Serial.begin(9600);
pinMode(OutputPin, OUTPUT);
}

void loop(){
  Serial.println("Sending");
 irsend.sendNEC(0x807F56A9, 32);
 delay(2000);
}

void sendNEC(unsigned long data, int nbits) {
 mark(NEC_HDR_MARK);
 space(NEC_HDR_SPACE);

 for (int i = 0; i < nbits; i++) {
   if (data & TOPBIT) {
     mark(NEC_BIT_MARK);
     space(NEC_ONE_SPACE);
   }
   else {
     mark(NEC_BIT_MARK);
     space(NEC_ZERO_SPACE);
   }
   data <<= 1;
 }
 mark(NEC_BIT_MARK);
 space(0);
}

void mark(int time) {
 digitalWrite(OutputPin, LOW);
 delayMicroseconds(time);
}

void space(int time) {
 digitalWrite(OutputPin, HIGH);
 delayMicroseconds(time);
}

The IR code is correct and responds correctly when actually using the remote so I am at a loss as to where I have gone wrong. Any ideas appreciated.

Thanks,
Jon

How do you know that the transmit hardware is working?

The sending software is modulating a ~38kHz carrier. The IR receiver hardware is demodulating the ~38kHz carrier. You can't bypass the demodulator in the receiver and expect the receiving software to work. Maybe you could put a low-pass filter in the line to 'demodulate' the signal.

Hi guys,

Thanks for the replies, I got it working with your input.

Aarg, I knew the codes where correct because I had used an IR transmitter attached to the arduino and the camera responded as expected.

Jon, the thread I linked used digitalWrite instead of IRsend so the output shouldn't have any modulation. But I hadn't spotted that the library uses the hex code to provide the modulation. I went back to the raw signal from IRrecvDump and that worked.

I stripped the minus from the result, put commas between the values and sent that as the output and it worked fine.

The test code I used below is:

//#include <IRremote.h>

unsigned int StartStop[68] = {8900,4300,650,1550,650,450,650,500,650,400,650,500,600,500,650,450,600,500,600,500,600,1600,700,1500,600,1550,650,1600,600,1600,650,1500,700,1500,650,500,600,1550,650,500,600,1550,650,500,600,1550,650,1550,650,500,600,1550,650,500,600,1600,600,500,600,1600,600,500,700,400,600,1600,650};
unsigned int Camera[68] = {8900,4300,650,1550,650,450,650,500,650,400,650,500,600,500,650,450,600,500,600,500,600,1600,700,1500,600,1550,650,1600,600,1600,650,1500,700,1500,650,500,600,1550,650,500,600,1550,650,500,600,1550,650,1550,650,500,600,1550,650,500,600,1600,600,500,600,1600,600,500,700,400,600,1600,650};
const int OutputPin = 3;



void setup(){
  Serial.begin(9600);
pinMode(OutputPin, OUTPUT);

Serial.println("Camera");
for (int i = 0; i < 68; i++) {
  if (i % 2) { //Set Mark
    digitalWrite(OutputPin, HIGH);
    delayMicroseconds( Camera[i] );
  }
  else {
    digitalWrite(OutputPin, LOW);
    delayMicroseconds( Camera[i] );    
  }
    
}
}

void loop(){
  


  Serial.println("Start Stop");

for (int i = 0; i < 68; i++) {
  if (i % 2) { //Set Mark
    digitalWrite(OutputPin, HIGH);
    delayMicroseconds( StartStop[i] );
  }
  else {
    digitalWrite(OutputPin, LOW);
    delayMicroseconds( StartStop[i] );    
  }
    
}
 delay(2000);
}