Friday 12 September 2014

Nikon Hacks Part III

Triggering Nikon with an Ultra Sound

Range-finding Sensor

SRF05 

 

 Introduction.


There are quite a few motion sensor hacks out there, but I wanted to do one for my new Nikon D5100 that was non-invasive and was completely detached from the camera. The D5100 is a high quality camera and takes great photos > 16MP and video in 1020p HD. This hack should work for any compatible IR and camera. Just hack the IR for your camera. There are cheap IR RC copies out there.
 
In the previous post I used
an arduino pin to a hacked Nikon IR remote. [http://gampageek.blogspot.co.uk/2014/09/nikon-hacks-part-i-i-triggering-nikon.html

Summary in pictures:








 

I used an old relay board I made for an earlier project, but a simple transistor circuit will do (see earlier post).

Now I want to use a sensor to detect and range a subject, before firing the IR to capture the subject on camera. I chose the SRF05 ultrasonic range-finder.

You can find the wiring and technical information for the SRF05 here:

Here is a brief video of the setup. First a side-view then to a view where I am outside of the scanning region of the SRF05. This front view dark because I am behind an object. I then "pop up" into the scanning region, within 200cm of the SRF05. The Camera focuses, the shutter opens and there is a flash, shutter closes. It does it twice in the time I am in the scanning region.




Triggered by a Subject in Range

Code:
---------------------------------------------------------------------------
int subjectRange = 200; // 200cm
const int numOfReadings = 5;                   // number of readings to take/ items in the array / readings to average
int readings[numOfReadings];                    // stores the distance readings in an array
int arrayIndex = 0;                             // arrayIndex of the current item in the array
int total = 0;                                  // stores the cumlative total
int averageDistance = 0;                        // stores the average value - using ints because 1cm or so is precise enough.

// setup pins and variables

int echoPin = 2;                                // SRF05 echo pin (digital 2)
int trigPin = 3;                                // SRF05 trigger pin (digital 3)
unsigned long pulseTime = 0;                    // stores the pulse in Micro Seconds
unsigned long distance = 0;                     // variable for storing the distance (cm)

int nikonPin = 8; // pin to trigger relay and IR unit



void setup() {


  pinMode(trigPin, OUTPUT);                     // set init pin 3 as output
  pinMode(echoPin, INPUT);                      // set echo pin 2 as input
  pinMode(nikonPin, OUTPUT);                   // sets pin 8 as output NikonPin
  digitalWrite(nikonPin, LOW);

  // create array loop to iterate over every item in the array

  for (int thisReading = 0; thisReading < numOfReadings; thisReading++) {
readings[thisReading] = 0;
 }

     Serial.begin(9600);
 }


void loop() {
// SRF05 code 
digitalWrite(trigPin, HIGH);                    // send 10 microsecond pulse
delayMicroseconds(10);                  // wait 10 microseconds before turning off
digitalWrite(trigPin, LOW);                     // stop sending the pulse
pulseTime = pulseIn(echoPin, HIGH);             // Look for a return pulse, it should be high as the pulse goes low-high-low
distance = pulseTime/58;                        // Distance = pulse time / 58 to convert to cm.
 total= total - readings[arrayIndex];           // subtract the last distance
readings[arrayIndex] = distance;                // add distance reading to array
total= total + readings[arrayIndex];            // add the reading to the total
arrayIndex = arrayIndex + 1;                    // go to the next item in the array
// At the end of the array (x items) then start again
if (arrayIndex >= numOfReadings)  {
    arrayIndex = 0;
  }

  averageDistance = total / numOfReadings;      // calculate the average distance
 
  Serial.println(averageDistance, DEC);         // print out the average distance to the Obj
  if (averageDistance <= subjectRange) // if subject comes to less than set distance take pictures until subject exits range
{
digitalWrite(nikonPin, HIGH); // trigger IR and camera
delay(2000); // allow some time (500 to 2000 seems to be ok for me)
digitalWrite(nikonPin, LOW); // IR off
}
else {
  digitalWrite(nikonPin, LOW); // default ir IR Off

}


}// end of loop

End of code: ---------------------------------------------------------------------------




No comments:

Post a Comment