Introduction to Arduino



LiDAR Camera Trigger



TF-Luna LiDAR Module beside a Micro SD card for scale



Overview:

    The TF-Luna LiDAR Module is a tiny (35mm X 21.25mm X 12.5mm), light weight (5g) and inexpensive (US $30.00) distance measuring device that allows you to create useful distance based projects on a budget.

    A LiDAR (Light Detection and Ranging) system calculates distance by sending out a pulse of light and waiting until it returns after bouncing off an object. This time delay between the light leaving and returning to the sensor is then divided in half and multiplied by the speed of light to determine a real-world distance to that object.

    This TF-Luna LiDAR Module emits an 850nm infrared beam of light (invisible to the human eye) and can calculate distances from 20cm out to 800cm. This project uses its distance measuring capability to trigger a camera when an object passes through a specific point in space. Unlike Double Break Beam triggers (described HERE), this LiDAR system allows us to place our sensor a good distance from our point of interest and does not require a frame to hold the 4 sensors required to determine a precise point in space.

    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 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.

    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 side of the trigger circuit with this method. The flash is triggered when the two wires are connected, and that's exactly what this 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




    Camera and Flash Trigger Setup



    More information about the camera trigger setup is available HERE .







TF-Luna LiDAR Module Wiring Setup


Install the TFLI2C (LiDAR) Library:

    You will need to install a library in order to communicate with the TF-Luna LiDAR Module, but this is a simple procedure and you only need to do it once. After opening the Arduino IDE, go to Tools / Manage Libraries and search for “TFLI2C”. Once you have located it simply click “Install” and you are done.



Install the TFLI2C Library to communicate with your TF-Luna LiDAR Module
Tools / Manage Libraries / Search for “TFLI2C”



Practical Application and Setup:

    Let us look at a situation where a system like this might come in handy. Say we would like to photograph a leopard but do not really want to sit there waiting in hopes of getting a shot of one. Wouldn’t it be nice if we could set up a simple system that would sit there all day (and night) recording images whenever a leopard (or another animal) enters your camera’s field of view? Sure, you would probably record images of many other creatures as well but that might be just as interesting.

    This system would be easy to set up. Once you have your system working properly, choose an area with a high likelihood of finding the creature you want to photograph. Once you have set the Trigger Zone in the code (Minimum and Maximum trigger distances from the LiDAR), set up the LiDAR sensor so the Trigger Zone is free of any other moving objects, and measure the distance from the sensor to the Trigger Zone. Focus your camera on that area by placing an object at that spot and then switch your camera to Manual Focus. Using manual focus is very important because the camera cannot focus quick enough to catch the moving animal (especially at night). If you are recording images with a flash, you can adjust the code to add a delay between images so the flash has enough time to recharge.

    Record a few test images to make sure you have sharp focus and enough depth of field to record the detail you want. Once you are satisfied with the setup you can let it run as long as you like and look forward viewing your results when you return.

    The TF-Luna‘s light beam has an illumination angle of approximately 2 degrees so the farther from the sensor the light travels, the wider the beam becomes. At a distance of 100cm the diameter of the light beam will be approximately 3.5cm and at a distance of 800cm (maximum range) the diameter will be approximately 28cm.



Trigger Zone



TF-Luna LiDAR Specifications:

    Operating Range: 20cm - 800cm (on a flat object with 90% reflectivity)
    Accuracy: ±6cm @ (20cm – 300cm), ±2% @ (300cm – 800cm) (on a flat object with 90% reflectivity)
    Distance Resolution: 1cm
    Frame Rate: Default is 100Hz but it can be set to 250Hz
    Ambient Light Immunity: 70Klux
    Operating Temperature: -10℃~60℃
    Light Wavelength: 850nm
    Field of View: 2 degrees
    Supply Voltage: 3.7V - 5.2V
    Power Consumption: ≤0.35W
    Dimensions: 35mm X 21.25mm X 12.5mm (L, W, H)
    Weight: 5g


Parts List:

    1 TF-Luna LiDAR Module
    1 Arduino UNO R3 (or similar microcontroller)
    1 Cable with a connector to fit your camera (for camera trigger)
    1 Additional Resistor (if required for camera trigger setup)
    1 PC817 Photocoupler (for camera trigger)
    1 330 Ohm Resistor (for camera trigger)
    1 Breadboard (for camera trigger)
    Connector Wires

    Information about the camera trigger setup can be found HERE



    Code to Trigger your Camera:
    Use this code if you just want to trigger the camera when the LiDAR beam is 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
      //-----------------------------------------
      
      //======================= Start of Settings ===================
      
      // *** Set the Minimum Distance trigger value (in cm) ***
      int Minimum_Distance = 100;
      
      // *** Set the Maximum Distance trigger value (in cm) ***
      int Maximum_Distance = 101;
      
      // *** Set the Delay value to wait for the camera's flash to recharge (in seconds) ***
      int delay_seconds = 5;
      
      //======================= End of Settings ====================
      
      #include <Arduino.h>
      #include <Wire.h>        // Including the Wire library
      #include <TFLI2C.h>      // Including the TFLI2C (TFLuna-I2C) Library (this needs to be installed)
      
      TFLI2C tflI2C;
      
      //Defining pin 13 for the Confirmation LED
      #define LED 13
      
      // Defining pin 4 for the Camera "Trigger" setup
      #define Trigger 4
      
      int16_t  Distance_cm;    // distance in centimeters
      int16_t  tfAddr = TFL_DEF_ADR;  // Use this default I2C address
       
      void setup(){
          Serial.begin(115200);  // Initalizing the Serial Port at a baud rate of 115200
          
          Wire.begin();          // Initalizing the Wire Library
          
          // setting pin 13 (the LED) as an output (this is also the pin for the UNO's on-board LED).
          pinMode(13,OUTPUT);
          pinMode(4,OUTPUT);
      
          // Turning pin 4 (Trigger) off
          digitalWrite(Trigger , LOW);
      }
       
      void loop(){
      
          digitalWrite(LED , LOW); // Turning off the LED (Pin 13)
        
          // Pulling a distance value (in cm) from the TF-Luna 
          tflI2C.getData(Distance_cm, tfAddr);
      
          // Write the distance to the serial monitor
          Serial.print("Distance (cm): ");
          Serial.println(Distance_cm);
      
      
          // Checking the distance for "In Trigger Zone"  LED
          // If the distance is above or equal to the Minimum and below or equal to the Maximum
          // turn onn the LED
          if ((Distance_cm >= Minimum_Distance) && (Distance_cm <= Maximum_Distance)){
          digitalWrite(LED , HIGH); // Turning on the LED (Pin 13) 
          }
          else{
          digitalWrite(LED , LOW); // Turning off the LED (Pin 13) 
          }
      
          // Checking the distance for Camera Trigger
          // If the distance is above or equal to the Minimum and below or equal to the Maximum
          if ((Distance_cm >= Minimum_Distance) && (Distance_cm <= Maximum_Distance)){
      
          // 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);
        }
      }
      
      //------------- Code Stops Here ----------------------------
      
      


    Code for Flash and Camera Trigger Setup:
    Use this code if you are triggering the flash units independently when the LiDAR beam is 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 beam is 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 Minimum Distance trigger value (in cm) ***
      int Minimum_Distance = 100;
      
      // *** Set the Maximum Distance trigger value (in cm) ***
      int Maximum_Distance = 101;
      
      // *** Set the Delay value to wait for the camera's flash to recharge (in seconds) ***
      int delay_seconds = 5;
      
      // Number of iterations before the camera records a new frame
      int iterations = 10000;
      
      //======================= End of Settings ====================
      
      #include <Arduino.h>     // Including the Arduino library
      #include <Wire.h>        // Including the Wire library
      #include <TFLI2C.h>      // Including the TFLI2C (TFLuna-I2C) Library (this needs to be installed)
      
      TFLI2C tflI2C;
      
      //Defining pin 13 for the Confirmation LED
      #define LED 13
      
      // Defining pin 4 as the "Camera Trigger"
      #define Camera_Trigger 4
      
      // Defining pin 5 as the "Flash Trigger"
      #define Flash_Trigger 5
      
      // Creating a variable called Counter and assigning it a value of 0
      int Counter = 0;
      
      int16_t  Distance_cm;    // distance in centimeters
      int16_t  tfAddr = TFL_DEF_ADR;  // Use this default I2C address
       
      void setup(){
        Serial.begin(115200);// Initalizing the Serial Port at a baud rate of 115200
          
        Wire.begin();// Initalizing the Wire Library
          
        // setting pin modes as outputs
        pinMode(13,OUTPUT);
          
        // 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);
      }
       
      void loop(){
      
        digitalWrite(LED , LOW); // Turning off the LED (Pin 13)
      
        // Open the camera's shutter 
        digitalWrite(Camera_Trigger , HIGH);
        
        // Pulling a distance value (in cm) from the TF-Luna 
        tflI2C.getData(Distance_cm, tfAddr);
      
        // Write the distance to the serial monitor
        Serial.print("Distance (cm): ");
        Serial.println(Distance_cm);
      
      
        // Checking the distance for "In Trigger Zone"  LED
        // If the distance is above or equal to the Minimum and below or equal to the Maximum
        // turn onn the LED
        if ((Distance_cm >= Minimum_Distance) && (Distance_cm <= Maximum_Distance)){
            
        // Trigger the Flash then close the shutter
        // Wait for the flash to recharge
        // Reset iteration counter to 0 and delay 500 milliseconds
          
        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