My first project (Lightning Detector Camera Trigger)

I guess this have been done a thousand times

Here is what I came up with (Writing the code by myself and learning component by component how to wire them with the Arduino. The code joins them all together)
Took a bit of code to define the writeln() function from that discussion:

Feel free to comment/give suggestions on the code!

Video of the setup in action (Unfortunately there is no lightning storm right now so I had to setup a fake lightning (100ms duration) on my monitor ;-))

A photo of the setup (Sorry for the messy desk ;-))

The code


  Benoit Lefebvre (
  Lightning detector camera trigger

#include <stdio.h>
char _str[32]; // 32 chars max!  increase if required to avoid overflow
#define writeln(...) sprintf(_str, __VA_ARGS__); Serial.println(_str)

const byte dPinTrigger = 12;        // Trigger LED Indicator
const byte dPinReady = 11;          // Ready LED Indicator
const byte dPinCamera = 8;
const byte aPinPot = 0;             // Potentiometer
const byte aPinLDR = 5;             // LDR

const int potMax = 1000;            // Maximum Potentiometer Value
const int potMin = 0;               // Minimum Potentiometer Value
const int diffMax = 10;             // Maximum LDR Difference to trigger
const int diffMin = 1;              // Minimum LDR Difference to trigger

const int delayAfterTrigger = 1000; // Delay after trigger (wait time)
const int delayHoldShutter = 100;    // Delay how long we hold the shutter

int potVal = 0;
int newLDRVal = 0;
int oldLDRVal = 0;

void setup() {
  pinMode(dPinTrigger, OUTPUT);
  pinMode(dPinReady, OUTPUT);
  pinMode(dPinCamera, OUTPUT);
  digitalWrite(dPinTrigger, LOW);
  digitalWrite(dPinReady, HIGH);
  digitalWrite(dPinCamera, LOW);
  oldLDRVal = analogRead(aPinLDR);

void loop() {
  // Read Potentiometer and LDR
  potVal = analogRead(aPinPot);
  newLDRVal = analogRead(aPinLDR);
  // Calculate lightning difference tolerance to trigger
  int diff = (int)(diffMin + ((potVal * (diffMax - diffMin)) / (potMax - potMin)));
  // Trigger the camera
  if ((newLDRVal - oldLDRVal) > diff) {

  // Debug to serial port if necessary
  //writeln("POT: %d   LDR: %d   DIFF: %d", potVal, newLDRVal, diff);

  oldLDRVal = newLDRVal;

void triggerCamera() {
  // Trigger camera at first!
  digitalWrite(dPinCamera, HIGH);
  writeln("CAMERA TRIGGERED!");
  digitalWrite(dPinReady, LOW);
  digitalWrite(dPinTrigger, HIGH);
  // Reset everything
  digitalWrite(dPinCamera, LOW);
  digitalWrite(dPinReady, HIGH);
  digitalWrite(dPinTrigger, LOW);
  // Read LDR before returning to loop
  oldLDRVal = analogRead(aPinLDR);

Looks pretty straightforward. Still waiting to try it?


interresting project (at least for me).

Couple of request though : - could you take some picture of the interface with the camera ? - can you evaluate the "speedness" of the system ? ... for example by puting a counting number on your computer screen (a number that would count up every 10 ms for example). Like this, you just have to look at your photo to know how fast did it take the picture.

Maybe this can help you. I saw a great similar project based on noise detection :

FIY, the guy locked his camera in full manual mode (focus on manual, aperture and shutter speed locked as well ... on flash).

CrossRoads, yes I'm still waiting to try it. Yesterday we were supposed to have a thunder storm but it did not happen :-(

Chrisprols For the camera interface I took a computer jumper that I modified to connect to the camera.. It's far from good, I have to hold the cable a certain way to make sure the connection works. I have ordered a couple of Canon camera trigger (with the N3 connector) on ebay.. they were around 90 cents each so I ordered 5 of those ;-) I will cut the cable and connect it to my circuit.

For the system speed, when I enable the mirror lock-up, here is what i get I realized that the screen was not refreshing fast enough so I build a small iOS application and I added a label that shows the elapsed time in seconds

On the 5D markII: 0.11 = 110ms reaction time

On the 1D markIV 0.07 = 70ms reaction time

I saw that project based on noise detection and this is something that I am interested to do too :-)

Everytimes you shoot with flash it's better to use manual mode for quick reaction time (for example, in a studio) For my shots I had to setup the cameras in manual setting and with mirror lockup for speed.