Lightning Shutter Trigger for a Camera

Update: Check out my latest Camera Axe project for a much more robust device that handles this.

From Public DomainI knew there were devices that could trigger a camera to fire during a lightning strike, but their circuits were more complicated than I wanted to make. I’m a software guy not a hardware guy so I decided to use an Arduino and that allowed me to write a little code that made the circuit much simpler.

Before I got started I looked at this wikipedia article about lightning so that I could verify this project would work. It has a lot of interesting information about lightning, but the most useful piece of data in the wikipedia article is the time lapse shot of a lightning strike. From the time lapse photo I was able to determine the duration of a lightning strike is about 100 ms. Then from this page I found my Canon 30d camera has a shutter lag of 65 ms. I know from a past project that if I use a reverse biased photo transistor to detect light it has a response time under 1 ms. The last piece of delay is the software running on the Arduino board and since it’s running at 16 MHz I am sure I can run a tight loop that takes under 1 ms. Adding up all the delays, I get 67 ms which is still much less than the 100 ms duration of a lightning strike so I was pretty confident this would work before I started work on the prototype.

The circuit I used to detect the light from the lightning was a very simple circuit that looked like the above circuit diagram. I used a cheap infrared photo transistor because that’s what Radio Shack had. I noticed that the sun, my house lights, and lightning all pump out plenty of infrared light for this circuit to detect. If this circuit is not sensitive enough try changing the value of the resistor. Larger resistance values should help sensitivity when there is only a little infrared light and smaller resistance values should help sensitivity when there is a lot of infrared light.

I also needed a circuit to trigger the camera. I already have written a short tutorial about how to do that here.

The last thing I needed to do was write some software. At first I thought I’d just have a threshold value that triggered the camera. That would work, but I’d need to calibrate the threshold value to different values depending on the environment. Instead I have the software look for a rapid change in the amount of infrared light detected. This works great because lightning causes a very rapid change.

Here is the code.

// Maurice Ribble
// 6-1-2008
// http://www.glacialwanderer.com/hobbyrobotics

// This code uses my camera trigger and lightning detector.
// It waits for a sudden change in the light intensity
// and then triggers the camera.

#define SHUTTER_PIN 7
#define LIGHTNING_TRIGGER_ANALOG_PIN 0
#define TRIGGER_THRESHHOLD 5

int lightningVal;

void setup()
{
  pinMode(SHUTTER_PIN, OUTPUT);
  digitalWrite(SHUTTER_PIN, LOW);
  Serial.begin(9600); // open serial

  lightningVal = analogRead(LIGHTNING_TRIGGER_ANALOG_PIN);
}

void loop()
{
  int cmd;
  int newLightningVal = analogRead(LIGHTNING_TRIGGER_ANALOG_PIN);
  Serial.println(lightningVal, DEC);

  if (abs(newLightningVal - lightningVal) > TRIGGER_THRESHHOLD)
  {
    digitalWrite(SHUTTER_PIN, HIGH);
    delay(1000); // May want to adjust this depending on shot type
    digitalWrite(SHUTTER_PIN, LOW);
    Serial.println("Shutter triggered");
  }

  lightningVal = newLightningVal;
}

Here are a few example pictures from Adam Bell. He used this blog to make a lightning shutter trigger. Traditionally lightning is captured at night. This lightning shutter trigger could do that (while you sleep), but where this device creates new opportunities is photographing lightning during the day. Peoples’ reflexes just are fast enough to get pictures like these. Thanks for the examples Adam!

Here’s a link to John’s Flicker page where he’s used this method to take some really nice lightning photos.

94 Comments

  1. cbrux71 said,

    July 27, 2010 @ 6:05 am

    Would this idea work in conjunction with an IR remote to trigger a pentax k-x? The pentax k-x doesnt have a jack for a cable so I was thinking of usung a IR remote and removing the depressable button and soldering 2 wires to the button contacts so the arduino could activate the IR remote? Any and all thought on this idea will be appreciated!

  2. Maurice Ribble said,

    July 27, 2010 @ 8:10 am

    cbrux71, that might work. It depends on how much extra lag this IR remote adds. My guess is that it would be fast enough, but I’m not sure.

    Also note that the remote’s button might work at a different voltage than the auduino. It’s best to check this. If it is the same voltage then as long as you connect the ground of the remote to the ground of auduino it should work. Another perhaps simpler option would be to use a transistor as a switch.

  3. cbrux71 said,

    July 27, 2010 @ 9:26 am

    Thanks for responding so quickly! I’m not sure what the voltage the remote works on would be but i can figure that out when I get it. I am somewhat uneducated in the workings of electronics so could you clarify what you mean by using a transistor as a swith? Like what kind of transistor and where would the transistor be locataed in the diagram?

  4. Maurice Ribble said,

    July 27, 2010 @ 3:26 pm

    Take one pin from the microcontroller and have it go through a 10K resistor and that goes to the base of the transistor. When you supply 5V current can flow from the collector to emitter otherwise no current flows. Here is a page that describes it: http://www.electronics-tutorials.ws/transistor/tran_4.html

    Here is a transistor I commonly use for this purpose: http://www.mouser.com/ProductDetail/Fairchild-Semiconductor/PN2222ATFR/?qs=sGAEpiMZZMtdAabcSkQOl4wFpopiDzZs

  5. Bob said,

    August 10, 2010 @ 2:15 pm

    cbrux71 … I was going to do this with my Nikon D50 that only has an IR trigger. The ir pulse train sequence for the Nikon ir remote is just about .2 seconds long from start to finish. Only chance on a Nikon would be to catch a secondary flash following close behind the first flash. Your Pentax is certainly different, but I bet it still is looking for a specific ir pulse train sequence. Good luck.

  6. Enlightening the Capture and Processing of Lightning said,

    September 10, 2010 @ 5:22 pm

    […] a program which runs the camera from a laptop (DSLR Remote). Some photographers even wire up an Arduino Circiut which detects the feeler strike and trips the shutter just before the main […]

  7. Desert Lightning said,

    October 22, 2010 @ 7:39 pm

    […] prototyping logic board that can do anything you can write code for. This dude made one as a lightning trigger for DSLRs. If you are a DIY'er you could probably build one for $75 or so, maybe less. […]

  8. justin said,

    October 23, 2010 @ 3:09 pm

    read the post and love the idea, being a photographer that hasn’t had much luck with lightning to this point. i understand the basics of the circuitry and mechanics of the project enough to get by. I understand what the code does but how do you actually get the code onto the Arduino chip?

  9. Andrew said,

    December 5, 2010 @ 6:43 pm

    I’m probably going to try building this soon, but I have a few questions.

    1) Has anyone tried building this for a nikon? Nikon’s 10 pin cable is more complex than the canon’s 3 pin cable. Nikon has a “signal ground” and a “power ground.” Not quite sure what to do with them.

    2)Does anybody have pictures of the final product? What kinda of case do you put the circuitry in?

  10. Maurice Ribble said,

    December 5, 2010 @ 8:25 pm

    I suggest looking at http://www.cameraAxe.com. It should have all the info you asked for including a pinout for the Nikon 10 pin cable. In the store I sell kits, but all the schematics/code are freely available if you’d rather build your own.

  11. John Groseclose said,

    January 14, 2011 @ 1:57 pm

    Yes, it works with a Nikon 10-pin.

    I had to slightly modify things because the tip and ring polarity on the regular “Pocket Wizard” shutter cables are reversed between the D80 cable and the 10-pin cable.

    Here’s my shot with a D80:

    http://www.flickr.com/photos/iaincaradoc/4870373245/

    And here’s a friend’s shot (about 100 feet to my right) of the same strike using a D300:

    http://www.flickr.com/photos/ckschweiger/4873301242/

    As you can see, the trigger-to-shutter delay makes for interesting differences.

  12. Larry Shields said,

    January 17, 2011 @ 11:54 pm

    I purchased an “Dale Beam IR and Audio” camera trigger back in the 80’s. I understand it’s no longer available. However, I was wondering if I could modify it some way and turn it into a “Lightning Trigger”? It looks and works like brand new. It’s a shame to see it go to waste…. Thanks…

  13. ThierryD said,

    February 17, 2011 @ 3:38 am

    There is another technics to capture ligthning.
    It’s to use the radio detection. The advantage of the radio detection, that is more speed from the light dectection.
    You can look that on this link : http://rienquepourlesyeux.free.fr/Detecteur%20de%20foudre/Lightning%20detector.htm.
    It is a lightning trigger sensor for DSLR camera.

  14. Gandalf said,

    March 24, 2011 @ 4:59 am

    Hi, nice arduino project any particular spec for the IR Phototransistor ? OP804 ? PT331 ?
    Angles ? rise time ?
    just found 15µ rise time IR Phototransistors !

    Thanks

  15. HolyDivar said,

    March 25, 2011 @ 12:12 am

    Essentially, you are monitoring the slope of the voltage waveform produced by the diode.
    I tested this code and it actually took the Arduino Uno about 2.37 ms to loop between reads.
    You can get this “slope sampling” down to a 115 microsecond sampling rate (loop duration) if you modify the code by removing the unnecessary serial prints.
    Also, I removed the “int cmd;” line and the “abs” in the ‘if’ statement since you are only interested in a steep increasing slope and the abs value will cause a trigger on both increasing and decreasing slopes.

    The analog read takes 100 microseconds so that takes up the majority of the loop duration.
    You can always add more delay by a “delayMicroseconds(n);” line.

    Here is the modified code:

    #define SHUTTER_PIN 7
    #define LIGHTNING_TRIGGER_ANALOG_PIN 0
    #define TRIGGER_THRESHOLD 5

    int lightningVal;

    void setup()
    {
    pinMode(SHUTTER_PIN, OUTPUT);
    digitalWrite(SHUTTER_PIN, LOW);

    lightningVal = analogRead(LIGHTNING_TRIGGER_ANALOG_PIN);
    }

    void loop()
    {
    int newLightningVal = analogRead(LIGHTNING_TRIGGER_ANALOG_PIN);

    if ((newLightningVal – lightningVal) > TRIGGER_THRESHOLD)
    {
    digitalWrite(SHUTTER_PIN, HIGH);
    delay(1000); // May want to adjust this depending on shot type
    digitalWrite(SHUTTER_PIN, LOW);
    }

    lightningVal = newLightningVal;
    }

  16. HolyDivar said,

    March 25, 2011 @ 12:19 am

    Gandalf,
    I put a powered photodiode with an internal op amp in the camera’s viewfinder. The diode is made by TAOS. model: TSL13S. It has a 9 us rise time from 0 – 90%. I also added a potentiometer to vary the threshold in my version. It takes another analog read, but the loop is still only 220 microseconds.

  17. Gandalf said,

    March 25, 2011 @ 10:54 am

    Oh ! i’ve got a lag time of 0.98 ms with Canon EOS350D ! I think it will be difficult to have impressive results !

    Regards

  18. Gandalf said,

    April 4, 2011 @ 3:51 am

    ok seems to work well but my phototransistor is IR sensitive centered on 940nm, damn !
    Changing this from my french supplier !

  19. David said,

    April 21, 2011 @ 11:44 am

    Instead the 2N2222 i used the Optocoupler 4N3
    and instead the 100kohm resistor i use 10kohm.

    I have some lag in the circuit. The camera (40D and 7D) trigger doesn’t capture the flash (430ex ii or YN460-ii).

    What could be the problem?
    Thank you.

  20. John Groseclose said,

    April 24, 2011 @ 1:46 am

    The flash duration of many battery-powered flashes at full power (the longest duration) is 1/1000 or shorter – the trigger detects the flash, and then your camera takes 45-70ms (the Canon 40D checks in at 59ms) to actually open the shutter. So, the flash is actually “over” by the time the shutter opens.

    Lightning strikes last 100-200ms, so you can actually get some of the strike in frame while the shutter is open.

  21. Maurice Ribble said,

    April 24, 2011 @ 5:48 am

    I just made a video about lightning photography: http://www.techphotoblog.com/tpb1-lightning-photography/

  22. David said,

    April 28, 2011 @ 9:14 am

    Thanks you John and Maurice.

    Now i will have to wait several months to test it (at real) 🙁
    I don’t get lightnings here so often.

  23. Lex Augusteijn said,

    May 4, 2011 @ 3:21 pm

    I have made the circuit and the shutter was triggered constantly in artificial indoor lighting (fluorescent).
    I found out that the light flicker (50Hz here, 60 in US), together with the long latency of the loop is the problem. The analogue read will sample the slope of the lighting every few ms and therefore trigger frequently. By increasing the threshold and the sample frequency (remove the serail print) it is also stable indoors.

    Lex

  24. Holydivar said,

    June 2, 2011 @ 12:48 am

    Yes, fluorescent lights will trigger it if the threshold is not set correctly, as will plasma/LCD screens, even with a very quick loop. It doesn’t matter whether it is an LCD that refreshes at 120 Hz, a plasma at 600 Hz, or a fluorescent bulb at 60 Hz, because it is the very quick rise time of the light turning on each time that causes the trigger. I have now gotten the loop duration down to 18 microseconds and the rise time of fluorescent/LCD/plasma will still trigger it. It’s actually a good test of the circuit. I demonstrate the circuit by waving a flashlight in front of the diode to show that I can never cause a quick enough change in light to trigger the shutter in this way, but if you point the flashlight directly at the diode and turn the light on, the quick change in light will trigger the shutter.

    A simple way around false triggering is to sense for near infrared light but not visible light by putting a long pass or band pass optical filter in front of the diode. (a cheap long pass filter >700’ish’ nanometers can be made from a piece of developed unexposed film, the part that looks pitch black to your eyes). Since lightning emits a broadband spectrum of light, the photodiode will still see lightning in the wavelengths longer than visible light waves but it won’t see the visible spectrum produced by fluorescent lighting/tv screens.

    To make the loop perform at the aforementioned 18 microseconds,
    you must change the prescaler for the Analog/Digital converter. The prescale value simply sets a divisor for the system clock (which is 16MHz for the arduino) to give the ADC a slower operating clock. By default, the prescale is set to 128 (16MHz/128 = 125 KHz). Since a conversion takes 13 ADC clocks, the sample rate is about 125KHz/13 or 9615 Hz.
    Setting the prescale to 16 will give the ADC a sample rate of 76900 Hz.

    An A/D conversion would normally take 100 microseconds and would take up a majority of the loop duration. This code will make it do a conversion in 1/8 of that time at 12.5 microseconds with no noticeable change in ADC accuracy.

    Also, this code eliminates the lag associated with using the ‘digitalwrite’ command by replacing that call with a direct port manipulation code. A digitalwrite command takes 10 microseconds to compute, while direct port manipulation takes 1/20 of that time at 0.5 microseconds.

    In my testing with an oscilloscope (http://www.flickr.com/photos/13900274@N02/5788769681/),
    I found that by using this code, the circuit response time from the time the diode senses a quick change in light to the time the shutter trigger signal was sent to the camera was about 15 microseconds, or 1/66,666 of a second.

    At a 15 microsecond response time, the circuit is about 14,000 times faster than the average human could respond. (assuming the average human response time is 215 milliseconds which is data obtained from http://www.humanbenchmark.com, go ahead – see what yours is.)

    Here is the code,

    //beginning
    #ifndef cbi
    #define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
    #endif
    #ifndef sbi
    #define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
    #endif

    int LIGHT_ANALOG_PIN = 0;
    int last_loop_light = 0;
    int this_loop_light = 0;
    int threshold = 10;

    void setup()
    {
    sbi(ADCSRA,ADPS2) ;
    cbi(ADCSRA,ADPS1) ;
    cbi(ADCSRA,ADPS0) ;

    DDRD = DDRB | B10000000;

    PORTD = B00000000;

    last_loop_light = analogRead(LIGHT_ANALOG_PIN);

    }

    void loop() {

    this_loop_light = analogRead(LIGHT_ANALOG_PIN);

    if ((this_loop_light – last_loop_light) > threshold)
    {
    PORTD=B10000000;
    delay(100);
    PORTD=B00000000;
    }

    last_loop_light = this_loop_light;
    }
    //end

  25. Troy said,

    June 3, 2011 @ 9:30 am

    I built this circuit, but haven’t had the opportunity to test it out with actual lightning. I did measure the response on an oscilloscope. With the two Serial.println commands included in the loop() section the response time to an led input was about 20 ms. If you remove the Serial.println commands then the response time becomes 0.2 ms! A big improvement!

  26. Holydivar said,

    June 3, 2011 @ 10:02 pm

    hmm, not sure why you might have gotten a 20ms response time.

    I got 4-5 ms response with original code http://www.flickr.com/photos/13900274@N02/5788769787/

    0.150 ms without serial http://www.flickr.com/photos/13900274@N02/5789323212/

    and 0.015 ms with the faster ADC code in my previous post http://www.flickr.com/photos/13900274@N02/5788769681/

  27. Florian said,

    June 13, 2011 @ 5:39 pm

    Hi guys

    Do you know if I could use such a setup to take pictures at nightclubs, using the strobe lights to trigger the shots? Or are those kind of flashes too fast?

    Florian

  28. Maurice Ribble said,

    June 13, 2011 @ 5:50 pm

    Florian, the problem would be shutter lag. The lag on your camera is much too long to capture strobes at a nightclub.

  29. Florian said,

    June 13, 2011 @ 7:27 pm

    Too bad.

    But maybe I could measure the time between the flashes, and activate the trigger on the 3rd flash just early enough? Or are they so fast I won’t be able to get the timing right?

    That’d make the project even more interesting…

  30. Maurice Ribble said,

    June 13, 2011 @ 7:41 pm

    Trying to get the 3rd flash is a really cool idea and it should work if the strobes are evenly spaced and far enough spaced that you have time to account for shutter delay. If the flashes are too closely spaced that isn’t a problem if there are more and you could hit a later flash. If you do anything like that please post the results. You might be interested in my more modern extension of this over at http://www.CameraAxe.com.

  31. Holydivar said,

    June 13, 2011 @ 8:47 pm

    Florian, try this circuit and play around with your camera’s exposure time to try to capture just one strobe flash. Start off with your camera’s quickest exposure and step it down until you capture the image you want.

    There is no need to know your exact measurements, however, you can find a close value to your camera’s shutter lag at:
    http://www.imaging-resource.com/CAMDB/compare_cameras.php
    and this circuit’s lag is negligible in comparison.
    If the shutter lag is consistent, you should be able to find the right exposure time to capture a single flash event.

    Good Luck!

    P.S. the above circuit that uses a photodiode in reverse bias can generate more than 5 volts (which is the maximum voltage suggested for arduino’s input pins.), so you are better off using a powered photodiode from TAOS or the like that will produce voltages within a restricted range of 0 to 5 volts.

  32. stephen said,

    November 17, 2011 @ 4:20 pm

    so how hard do you think it would be to set this up with the wireless function of the rebel xti?

  33. Frank said,

    February 2, 2012 @ 6:41 pm

    Holydivar, I am waiting on my Arduino Uno to arrive to begin my first such project. I plan on using the code you posted based on the expert research that went in to it.
    Two things… You mention using a “Powered Photo Diode” which would be less stressful on the Arduino inputs. Can you please be more specific with a recommendation?
    Ultimately I plan to move my project to a ATtiny 45 or 85 microcontroller…. See here>>(http://hlt.media.mit.edu/?p=1229)
    These chips run at 20MHz vs the 16MHz the Arduino runs at. Are there any changes to your code that I would have to make?

  34. Tony Roberts said,

    February 15, 2012 @ 10:29 am

    Hi
    I’m a little confused by the use of reverse biasing. In the first diagram of this blog, the word is phototransistor but the symbol is a diode. Everything I read about phototransistors says you don’t reverse bias them. Perhaps this is why people were complaining about low sensitivity?
    Regards
    Tony Roberts

  35. DIY Pentax IR Lightning Trigger « New Hardpan said,

    February 27, 2012 @ 3:14 pm

    […] The page I found that contained his early lightning trigger using Arduino is here. […]

  36. DIY Lightning Trigger for Digital Cameras « Hardpan.com said,

    March 14, 2012 @ 10:42 am

    […] There are many other people on the internet that have used micro-controllers to make triggers. My inspiration for this trigger is based on information I found online (here). […]

  37. 555 timer Tutorials said,

    March 15, 2012 @ 12:52 pm

    great job. now i know how to use infrared photo transistor and arduino.. thanks for this project
    if you have time check out my lens on BJT..also expectin a comment…
    http://www.squidoo.com/how-bipolar-junction-transistor-works

  38. DIY Pentax IR Lightning Trigger Version 3 « Hardpan.com said,

    March 19, 2012 @ 8:55 pm

    […] The input code is based on information from Maurice Ribble who makes the CameraAxe (a wonderful camera trigger for anyone who has a wired connection for the shutter trigger, and would rather purchase a complete trigger mechanism).  The page I found that contained his early lightning trigger using Arduino is here. […]

  39. DIY Pentax Wireless IR Lightning Trigger Version 4 « Hardpan.com said,

    March 19, 2012 @ 10:45 pm

    […] The input code is based on information from Maurice Ribble who makes the CameraAxe (a wonderful camera trigger for anyone who has a wired connection for the shutter trigger, and would rather purchase a complete trigger mechanism). The page I found that contained his early lightning trigger using Arduino is here. […]

  40. grubbs said,

    May 30, 2012 @ 5:06 pm

    how hard is this for someone who has no experience in this area at all?

  41. ayasystems said,

    June 1, 2012 @ 5:21 am

    Hi.

    I want share with you my modifications with you. Thanks!

    // Maurice Ribble
    // 6-1-2008
    // http://www.glacialwanderer.com/hobbyrobotics

    // This code uses my camera trigger and lightning detector.
    // It waits for a sudden change in the light intensity
    // and then triggers the camera.

    #define SHUTTER_PIN 7
    #define LIGHTNING_TRIGGER_ANALOG_PIN 0
    #define TRIGGER_THRESHHOLD 5
    #define STATE_LED 13

    int lightningVal = 0;
    // Variables will change:
    int shootTime = 1000; // May want to adjust this depending on shot type ms
    long previousMillis = 0; // will store last val was update
    long interval = 5000; // interval to update light reference value ms

    void setup()
    {
    pinMode(SHUTTER_PIN, OUTPUT);
    pinMode(STATE_LED, OUTPUT);
    digitalWrite(STATE_LED, LOW);
    digitalWrite(SHUTTER_PIN, LOW);
    Serial.begin(9600); // open serial
    readValue();
    }

    void loop()
    {
    int cmd;
    int newLightningVal = analogRead(LIGHTNING_TRIGGER_ANALOG_PIN);
    Serial.println();
    Serial.print(“Store light: “);
    Serial.print(lightningVal, DEC);
    Serial.print(” Actual light: “);
    Serial.print(newLightningVal, DEC);
    Serial.println();
    if (abs(newLightningVal – lightningVal) > TRIGGER_THRESHHOLD)
    {
    Serial.println(“=================”);
    Serial.println(“Shutter triggered”);
    Serial.println(“=================”);
    digitalWrite(SHUTTER_PIN, HIGH);
    digitalWrite(STATE_LED, LOW);
    delay(shootTime); // May want to adjust this depending on shot type
    digitalWrite(SHUTTER_PIN, LOW);
    digitalWrite(STATE_LED, HIGH);

    }

    unsigned long currentMillis = millis();

    if(currentMillis – previousMillis > interval) {
    // save the last time you blinked the LED
    previousMillis = currentMillis;
    readValue();
    }
    }

    void readValue(){
    Serial.println(“Refresh Value”);
    lightningVal = analogRead(LIGHTNING_TRIGGER_ANALOG_PIN);
    }

  42. Melani said,

    July 26, 2012 @ 2:35 pm

    I have the first original program for the lightning trigger in my arduino. If I want to modify it to work with a laser trigger and fire the camera when the beam is broken instead of when it reconnects, how would I do that?

  43. lacrosse1991 said,

    August 14, 2012 @ 5:42 pm

    Hello, with the photo transistor you use in this project, could someone please post a link to it as i’ve tried one that I bought from radioshack, but while testing it, it only seemed to work if the lightsource was pointed directly at the top of the transistor, from the side it did nothing, here is the one I’ve used http://www.radioshack.com/product/index.jsp?productId=2049724 which did not work well, although i gave a photocell/photoresistor a try and it worked perfectly, although when the time comes for capturing lightning i would prefer to have a faster response time, so if someone could give me a link to the phototransistor that they have used I would really appreciate it, thanks!

  44. Daniel said,

    August 16, 2013 @ 6:30 am

    Hi, my nikon can only be triggered by connecting the yellow adn the red wiring together with the white cabel at the same typ, will this circuit be able to do so?

    /Daniel

RSS feed for comments on this post