emulate IR-Remote

Hi,

I want to control my camera (Nikon D80) with the Arduino to automatically “scan” my negatives. Therefor I connected an IR-LED to PIN 13 and wrote this program:

#define output1 13
int c = 0;
int cg = 0;

void setup()
{
pinMode(output1,OUTPUT);
}


void loop()
{
//send the signal 2 times with a delay of 63ms
 for (cg=0; cg<=1; cg++)
{   
   digitalWrite(output1,LOW);
   delay(63);
   
   //on for 2000us
    for (c=0; c<=77; c++)
    {
    digitalWrite(output1,HIGH);
    delayMicroseconds(13);
    digitalWrite(output1,LOW);
    delayMicroseconds(13);
    }
    
    //off for 27830us - took 3 delays, because more than 16000us per delay are not precise, sais the referenceguide
    digitalWrite(output1,LOW);
    delayMicroseconds(10000);
    delayMicroseconds(10000);
    delayMicroseconds(7830);
    
    //on for 390us
    for (c=0; c<=15; c++)
    {
    digitalWrite(output1,HIGH);
    delayMicroseconds(13);
    digitalWrite(output1,LOW);
    delayMicroseconds(13);
    }
    
    //off for 1580us
    digitalWrite(output1,LOW);
    delayMicroseconds(1580);
    
    //on for 410us
      for (c=0; c<=16; c++)
    {
    digitalWrite(output1,HIGH);
    delayMicroseconds(13);
    digitalWrite(output1,LOW);
    delayMicroseconds(13);
    }
    
    //off for 3580us
    digitalWrite(output1,LOW);
    delayMicroseconds(3580);
    
    
   //on for 
    for (c=0; c<=15; c++)
    {
    digitalWrite(output1,HIGH);
    delayMicroseconds(13);
    digitalWrite(output1,LOW);
    delayMicroseconds(13);
    }
 digitalWrite(output1,LOW);
 
 
 }
     
 delay(2000);
  
}

If the LED is on, it has to be modulated with 38kHz [ch8776] 13us on, 13us off. When its off, its completely off.

I got the pattern (signal) from
http://www.bigmike.it/ircontrol/
(the D70 uses the same IR as the D80 as far as I know)

Sadly it doesnt work at all. If I put a normal LED in there, I see that it is lit, but the camera doesnt shoot a picture. Could it be, that the timing isnt accurate enough with these counters I used? Is there another way to do this?

But he says:
" The D70 does not appear to be picky about the timings (± a few 100us here and there…), and even the modulation freq can be different from 40kHz " ( http://users.tkk.fi/~jwagner/electr/d70remote/ )
so it doesnt have to be that accurate…

thx!

Hello,

We have the same kind of disucssion in the french forum. But for a canon remote http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1198598252

I see in the reference http://www.arduino.cc/en/Reference/Millis that to achieve a 38khz your waits should be more like 9us because of the delay of triggering the digitalWrite instruction.

This said my remote does not work either :-)

Hope this help.

I had problems with the digitalWrite function taking too long as well. Instead I resolved to just writing to the pin control register. I suggest you take a look at the code I posted here, but download the version with comments.

Use the ir_raw_write_low and ir_raw_write_high functions to create the waveform for your specific device. Please note the parameter requirements for these functions, the pin parameter is not as you might expect. Instead, these functions require the pin parameter to be of the form: pin = (1 << actual_pin) where actual_pin is the digital pin number that controls your IR LED and is between 0 and 7.

Hope that helps!

@deldude
I tried the 9us-hint but it didnt work for me either. And I dont speak French that well :frowning:

@
I studied your code and worked it out. I just used ir_raw_write_low/high as suggested and it just works! Thx a big bunch! I would have never figured that out myself.