Skip to main content

Nikon Infra red remote

Posted in

Hello, can somebody use anything from this code to help with this project.
i began building a panoramic head with an arduino and servo for use with my Nikon D50 a while ago using various bits of code (this was my first arduino project)
i will post some photos when i get back into it.
i have not used the project for a while then i came acoss this forum..
my heart stopped.. last week i sold a broken 42" wide format plotter on eBay. would have made a perfect rail/dolly if i had found this first!!

/*
LUCKYLARRY.CO.UK - IR Remote control for Nikon using Arduino
 Mimics the infrared signal to trigger the remote for any Nikon camera
 which can use the ML-L1 and ML-L3 remotes. Can be used as an intervalometer
 for time lapse photography.
 */

#include <Servo.h>
#include <LED.h>

Servo myservo;                          // create servo object to control a servo
// a maximum of eight servo objects can be created
const int buttonPin = 2;
int timer = 100;           // The higher the number, the slower the timing.
int ledPins[] = {
  12, 11, 9, 8, 7, };       // an array of pin numbers to which LEDs are attached
int pinCount = 5;           // the number of pins (i.e. the length of the array)
int buttonState = 0;
int pos = 0;                          // variable to store the servo position
int pinIRLED = 13;                    // assign the Infrared emitter/ diode to pin 13
int potpin = 0;                      // analog pin used to control step sizes
int potpin2 = 1;                     // analog pin used to control delay
int val;                            // variable to read the value from the steps pin
int val2;                           // variable to read the value from the delay pin
int shots;                          // calculate number of moves from val
int remain;                        // calculate remaining shots

LED led = LED(3);
LED ledred = LED(5);
LED ledgreen = LED(6);
void setup() {
  int thisPin;
  // the array elements are numbered from 0 to (pinCount - 1).
  // use a for loop to initialize each pin as an output:
  for (int thisPin = 0; thisPin < pinCount; thisPin++)  {
    pinMode(ledPins[thisPin], OUTPUT);      
  }
  Serial.begin(9600);
  myservo.attach(10);                // attaches the servo on pin 10 to the servo object
  pinMode(pinIRLED, OUTPUT);     // set the  IR pin as an output
  pinMode(buttonPin, INPUT);
  Serial.println(" Uveco camera timer Mk4");
  Serial.println(" For Nikon DSLR");
  Serial.println(" READY TO BEGIN");  
  Serial.println("  ");
 
}
// sets the pulse of the IR signal.
void pulseON(int pulseTime) {
  unsigned long endPulse = micros() + pulseTime;        // create the microseconds to pulse for
  while( micros() < endPulse) {
    digitalWrite(pinIRLED, HIGH);                       // turn IR on
    delayMicroseconds(13);                              // half the clock cycle for 38Khz (26.32×10-6s) - e.g. the 'on' part of our wave
    digitalWrite(pinIRLED, LOW);                        // turn IR off
    delayMicroseconds(13);                              // delay for the other half of the cycle to generate wave/ oscillation
  }
}
void pulseOFF(unsigned long startDelay) {
  unsigned long endDelay = micros() + startDelay;       // create the microseconds to delay for
  while(micros() < endDelay);
}
void takePicture() {
  for (int i=0; i < 2; i++) {
    pulseON(2000);                                      // pulse for 2000 uS (Microseconds)
    pulseOFF(27850);                                    // turn pulse off for 27850 us
    pulseON(390);                                       // and so on
    pulseOFF(1580);
    pulseON(410);
    pulseOFF(3580);
    pulseON(400);
    pulseOFF(63200);
  }
}
void lightsequence() {                                  // light sequence for before shot
  {

    Serial.println("ok to move");
    delay(500);
    led.fadeIn(2000);  
    delay(1500);
    Serial.println("SMILE!!");
    ledred.blink(250,10);
    led.fadeOut(2000);
    ledred.fadeOut(2000);
    delay(1200);

  }                              
}
void lightsequence2() {                                  // light sequence for after shot
  {
   

    led.blink(15,12);
    ledred.blink(15,6);
    ledgreen.blink(15,6);
    led.blink(10,12);

  }                              
}
void loop() {
 
  if (buttonState == HIGH) {    
    takePicture();}
    ledgreen.fadeIn(1500);
  val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023)
  val = map(val, 0, 1023, 0, 90);     // scale it to use it with the servo (value between 0 and 180/2)
  for(pos = 0; pos < 180; pos += val)  // goes from 0 degrees to 180 degrees

  {  
    ledgreen.blink(100,10);
    myservo.write(pos);     // tell servo to go to position in variable 'pos'

    lightsequence();
    takePicture();
    lightsequence2();
    Serial.println(" Picture taken!");// loop from the lowest pin to the highest:
  for (int thisPin = 0; thisPin < pinCount; thisPin++) {
    // turn the pin on:
    digitalWrite(ledPins[thisPin], HIGH);  
    delay(timer);                  
    // turn the pin off:
    digitalWrite(ledPins[thisPin], LOW);    

  }

  // loop from the highest pin to the lowest:
  for (int thisPin = pinCount - 1; thisPin >= 0; thisPin--) {
    // turn the pin on:
    digitalWrite(ledPins[thisPin], HIGH);
    delay(timer);
    // turn the pin off:
    digitalWrite(ledPins[thisPin], LOW);
  }

    val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023)
    val = map(val, 0, 1023, 0, 90);     // scale it to use it with the servo (value between 0 and 180)
    shots = (180/val);

    Serial.println(shots);

    delay(1500);
    Serial.println(" and relax");

  }

}