Introduction to Arduino



Double Break Beam Camera Trigger



5mm IR Break Beam Sensor Set. Emitter (left), Receiver (right)
Wiring: Red (5V Power), Black (Ground), Yellow (Sensor data)



Overview:

    Creating an Arduino double break beam camera trigger system is probably easier than you think.

    With a few basic parts and the code supplied below you will be able to make a system that automatically triggers your camera when an objects passes through a precise point in space. If you have your camera focused on that point you should be able to record interesting images without any actions on your part.

    Wiring is quite simple. All you need to do is have the red wires from the sensors connected to power pins of your Arduino (5V), the black wires connected to Ground pins, and the yellow wires (one from each receiver sensor) attached to different pins on the Arduino (Pins 2 and 7 in this case).

    These 5mm break beam sensors have a maximum range of 50cm so you will need to keep your setup quite compact. I used a 40cm X 40cm frame for this example.

    The transmitter has a 10° angle of illumination so you need to make sure your receiver falls within this angle of illumination.

    NOTE: Due to the time delay between the camera being triggered and it recording an image (due to the relatively slow shutter response times of most cameras), this system may not be useful for recording images of fast-moving objects. Test its effectiveness for your application before deploying the setup.

    To achieve faster image captures you could trigger a flash directly and bypass the camera trigger altogether. Unfortunately, this means you would need to have the shutter remain open for a long period of time while waiting for something to trigger an image which will probably increase the background exposure in your image. You could use a low ISO (100), a small lens aperture like F22 and record images at night with a black background to help decrease this background exposure. This method could also be used in a dark room with all the lights turned off.




40cm X 40cm Double Break Beam Frame Setup



Setup:

    Cut some PVC tube into 4 even lengths but make sure they are each less than 50cm in length (this is the maximum range of these break beam sensors). Use the PVC corners to create your frame.

    Attach one emitter and one receiver to opposite sides of the frame (attach the other pair to the remaining sides in a similar fashion).

    Attach all the RED wires to 5V on the Arduino.

    Attach all the BLACK wires to Ground on the Arduino.

    Attach one YELLOW wire to Pin 2 on the Arduino.

    Attach the other YELLOW wire to Pin 7 on the Arduino.

    Attach the TRIGGER circuit to Pin 4 on the Arduino. Information about the camera trigger setup is available HERE .

    Set the delay interval between images to allow the flash to recharge (default is 5 seconds). This setting is in the top part of the code.

    Upload the supplied code to your Arduino.

    Test your system to make sure the camera is triggered when both beams are interrupted. You can now turn off your Arduino.

    Set up your frame and make it as stable as possible.

    Set up your camera and make sure your area of interest in within the frame.

    Set your camera to Manual Focus and focus at the approximate position where the two beams cross. You can hold an object at that position to help you focus. Remove the object.

    Turn your Arduino and Camera on.

    Test the trigger by moving something through the point where the beams crosses.

    Check the image and adjust the framing, focus, aperture (for depth of field) and exposure.

    Make a few test images to ensure the system is working properly.

    Have fun.




    40cm X 40cm Double Break Beam Frame Setup Completed (Camera Trigger Setup)




    Double Break Beam Controller and Wiring Setup (Camera Trigger Setup)




    Setup Mounted on a Portable Workbench



    An easy way to connect the trigger directly to a flash is to pick up an inexpensive flash hot shoe adapter with a “sync cord” connector (the small round connector port shown in the image below). All you need to do is strip the two wires in the sync cord and attach them to the camera side of the trigger circuit (shown below). You don’t need a resistor in the flash trigger circuit when using this method. The flash is triggered when the two wires are connected, and that is exactly what this flash trigger circuit does. This system will give much quicker image capture times compared to relying on the in-camera shutter mechanism.




    Hot Shoe Adapter with a “Sync Cord” Connector




    Flash and Camera Trigger Setup
    (for fast moving objects)




    Camera Trigger Setup (flash is triggered by the camera)
    (for slower moving objects)

    More information about the camera trigger setup is available HERE .




    Flash Trigger Setup In Action
    Camera shutter open (bulb setting) with the flash being triggered directly

    More information about the camera trigger setup is available HERE .





Parts List:

    2 meters of 1/2 inch PVC pipe
    4 90 degree corners for 1/2 inch PVC pipe
    2 pair of 5mm IR Break Beam Sensors
    1 PC817 Photocoupler
    1 330 Ohm Resistor
    1 Additional Resistor (if required for camera trigger setup)
    1 Cable with a connector to fit your camera
    1 Arduino UNO R3 (or similar microcontroller)
    1 Breadboard
    Connector Wires

    Information about the camera trigger setup can be found HERE


Code for Camera Trigger:
Use this code if you just want to trigger the camera when the two beams are broken. A new image will be recorded every time the beams are broken. Due to the relatively long delay in most camera shutter systems, this may not be appropriate for fast moving objects.


    //------------- Code Starts Here ----------------------------
    
    //-----------------------------------------
    //Published by IntroductionToArduino.com
    //Created by Paul Illsley (www.paulillsley.com)
    //Please use and share so others can enjoy
    //-----------------------------------------
    
    // *** Set the “delay_seconds” value (in seconds) for camera's flash to recharge ***
    int delay_seconds = 5;
    
    // Defining pin 7 as Sensor _1
    #define Sensor_1 7
    
    // Defining pin 2 as Sensor _2
    #define Sensor_2 2
    
    // Defining pin 4 as the camera "Trigger"
    #define Trigger 4
    
    // Creating two integer variables, one for each beam
    int Beam_1 = 0;
    int Beam_2 = 0; 
    
    void setup() {
         
      // Declaring pin 4 (Trigger) as an output
      pinMode(Trigger , OUTPUT);
    
      // Turning pin 4 (Trigger) off
      digitalWrite(Trigger , LOW);
      
      // Initialize the sensor pins as an inputs:
      pinMode(Sensor_1, INPUT);
      pinMode(Sensor_2, INPUT);
    
      // Turning on the pullup resistor for each sensor
      digitalWrite(Sensor_1, HIGH);
      digitalWrite(Sensor_2, HIGH);
    }
    
    void loop(){
        // Read the state of both pin values:
        Beam_1 = digitalRead(Sensor_1);
        Beam_2 = digitalRead(Sensor_2);
    
        // Check to see if both beams are broken (both values are 0)
        if ((Beam_1 == 0) && (Beam_2 == 0)){
    
        // If both are broken, record an image (Trigger)
        digitalWrite(Trigger , HIGH); // Turning on pin 4 (Trigger)  
        delay(100); // Delaying 100 milliseconds
        digitalWrite(Trigger , LOW); // Turning off pin 4 (Trigger)
        
        // Delay a set period of time (delay_seconds) to let the camera's flash recharge
        delay((delay_seconds*1000)-100);
    
      }
    }
    
    //------------- Code Stops Here ----------------------------
    
    
    


Code for Flash and Camera Trigger Setup:
Use this code if you are triggering the flash units independently when the beams are broken. If you set your camera on “Bulb” mode, the code will expose an image and cycle through the loop until it reaches a specified number of loops (iterations), then a new frame will be started. If the beams are broken anytime during the specified number of iterations, the flash will trigger and a new image will be started. Because the shutter is being left open for a long period of time, you need to be photographing in a dark area with a dark background so the image does not get exposed by ambient light.


Powerup Sequence: Tun on the camera, then turn on the Arduino.


//------------- Code Starts Here ----------------------------

//-----------------------------------------
//Published by IntroductionToArduino.com
//Created by Paul Illsley (www.paulillsley.com)
//Please use and share so others can enjoy
//-----------------------------------------

//======================= Start of Settings ===================

// *** Set the “delay_seconds” value (in seconds) for camera's flash to recharge ***
int delay_seconds = 5;

// Number of iterations before the camera records a new frame
int iterations = 5000;

//======================= End of Settings ====================

  // Defining pin 7 as Sensor _1
  #define Sensor_1 7

  // Defining pin 2 as Sensor _2
  #define Sensor_2 2

  // Defining pin 4 as the "Camera Trigger"
  #define Camera_Trigger 4

  // Defining pin 5 as the "Flash Trigger"
  #define Flash_Trigger 5

  // Creating two integer variables, one for each beam
  int Beam_1 = 0;
  int Beam_2 = 0; 

  // Creating an integer variable for the counter (count number of iterations)
  int Counter = 0;

void setup() {
     
  // Declaring pin 4 (Camera_Trigger) as an output
  pinMode(Camera_Trigger , OUTPUT);

  // Declaring pin 5 (Flash_Trigger) as an output
  pinMode(Flash_Trigger , OUTPUT);

  // Turning pin 4 (Camera_Trigger) off
  digitalWrite(Camera_Trigger , LOW);
  
  // Initialize the sensor pins as an inputs:
  pinMode(Sensor_1, INPUT);
  pinMode(Sensor_2, INPUT);

  // turning on the pullup resistor for each sensor
  digitalWrite(Sensor_1, HIGH);
  digitalWrite(Sensor_2, HIGH);
  Serial.begin (9600);

}

void loop(){

  // Open the camera's shutter 
  digitalWrite(Camera_Trigger , HIGH);
     
  // Read the state of both pin values:
  Beam_1 = digitalRead(Sensor_1);
  Beam_2 = digitalRead(Sensor_2);
  
  // If both beams are broken
  if ((Beam_1 == 0) && (Beam_2 == 0)){

  // Trigger the Flash then close the shutter
  // Wait for the flash to recharge
  // Reset iteration counter to 0 and delay 500 milliseconds
  // More information about this step can be found at:
  // https://www.paulillsley.com/arduino/camera_trigger.html
    
  digitalWrite(Flash_Trigger , HIGH);
  delay(10);
  digitalWrite(Flash_Trigger , LOW);
  digitalWrite(Camera_Trigger , LOW);
  delay((delay_seconds)*1000); 
  Counter = 0;
  delay(500);
}

  // If the number of iterations is reached without being triggered, 
  // triggeer the camera to open a new frame and reset the counter to 0
  // Delay 500 milliseconds
  if (Counter == (iterations)){
  digitalWrite(Camera_Trigger , LOW);
  Counter = 0;
  delay(500);
}

  // If the camera isn't triggered, add one to the counter value
  Counter = Counter + 1;

  // Print the iteration count number
  Serial.println(Counter);

}

//------------- Code Stops Here ----------------------------



Created by Paul Illsley

Return to www.introductiontoarduino.com