Narzędzia użytkownika

Narzędzia witryny



I'll describe here how to build a phototrigger device.

Recent changes:

  • 2009-12-20 - corrected bug related with encoder (accidental left/right keypresses) + corrected Yes/No „dialog”.



  • periodically shots a photo allowing time lapse photography (can be combined with bulb mode), max time between photos: 99 h 59 m 59 s,
  • bulb time (maximum 99 h 59 m 59 s),
  • postponed start (up to 24 h in advance),
  • powered by 2 AA(A) batteries (3V),
  • 2 × 16 characters LCD display + encoder for easy control,
  • easy to use software,
  • minimal number of components, small PCB,
  • RTC clock (no calendar),
  • low battery indicator.


Device uses ATMEL's atmega168 micro controller (at the time of writing this article code uses more than 12 kB of flash memory) + few passive and active peripherals. Schematics:

phototrigger schematics

Device should be powered by 3 V, i.e. two 1,5 V batteries, it is possible that it could run with two 1,2 V batteries but that haven't been tested. Big power capacitor allows battery exchange before processor runs out of power. When active, device uses, highest backlight level, about 70 mA; when backlight is off: 1-2 mA; when off (RTC keeps running) about 50 µA (if my multimeter is correct). MCU is driven by internal calibrated RC set to 1 MHz. RTC is done entirely in software, only external „watch” crystal is used (32.768 kHz). There's voltage battery measurement circuit, the potentiometer should be set so that on ADC5 measures 1/4 of power supply (3 V ⇒ 0,75 V). LCD contrast is directly connected to OC0A PWM output, LCD backlight is also driven by PWM output (OCA1) through N-MOSFET transistor (BS170). LCD itself is connected entirely to PORTB. Shutter release circuit can be either a BS170 MOSFET (some may say it's more „dangerous” option) or an optotransistor for perfect isolation from the camera (disadvantage: uses more power due to LED in optoelement). User input is done through an ALPS (or compatible) encoder with switch, encoder and switch noise filtering is done by software. I've found than BS170 works perfectly. Mini jack connector is used as output. Board is using 6 pin ISP connector.

Fuse configuration for CPU is factory's default: 8 MHz internal RC clock + CKDIV8 ⇒ gives 1 MHz system clock. Remember to program EEPROM memory (.eep file), this file contains start/default values. Here's screenshot for fuses for reference (don't mind that the title says it's for atmega88):

atmega168 fuses configuration


Board is 100 mm x 41 mm. PCB has one copper layer with couple of connections on top layer. There are very little components to mount. Remember to use either optotransistor or MOSFET (see below for more details). Mounting of ISP connector is optional if you can program MCU in external programmer. Remember to use 3 V compatible LCD Display 2 × 16 characters), preferred is the model which is readable even when the backlight is turned off. When programming MCU remember to program also EEPROM memory (it contains default values). Before start set 1/4 of supply voltage on ADC5 using R2 (0.75 V for 3 V supply /2 batteries/).

For optotransistor option: mount IC2 (optotransistor) and R3, do not mount T1, J1 should not be short cut. R3 value depends on IC2 used (on schematics CNY17, but any other optotransistor can be used), normally it should be around 220 Ohm.

For N-MOSFET option: mount T1 and short cut J1 (bottom side), do not mount IC2 and R3.

To connect to camera use 1:1 cable:

phototrigger to camera connector

Photo of a PCB board (please note that this is „b” version of PCB which slightly differs from the current version „c”):

phototrigger elements on PCB board

phototrigger with all elements


Software was written entirely in c and compiled using avr-gcc. It uses modified example code from avr-libc site as well as tinymenu library. Binary size is more than 12 kB.

Code is well documented, I will describe briefly what's where. There are many files which control different parts of the device, here's a list with brief description:

  • dlg.c/h - code responsible for high level LCD operations (displaying of info screen, editable screens),
  • eeprom.c/h - contains addresses of variables contained in EEPROM memory,
  • enc.c/h - keyboard functionality, get last pressed key (switch, left rotation, right rotation),
  • hd44780.c/h - low level functions for LCD display,
  • hw.c/h - low level configuration of hardware, power off handling,
  • lcd.c/h - higher level functions for LCD (clear screen, cursor location, putting character, backlight),
  • main.c - entry function (main() ), initialisation after power on, calls startPT(),
  • pt.c/h - core logic for the device (menu, menu handling functions),
  • rtc.c/h - real time clock, static timer handling, utility functions related with time,
  • tinymenu.c/h, tinymenu_hw.h - menu library (slightly modified to suite phototrigger needs).

Source files contain function bodies, header files contain constant (#define-s) which may influence how phototrigger works, ex. encoder rotation sensitivity, inactivity time out, etc.

After power on hardware is initialised (hwSetupAll()) CPU enters power save mode (hwEnterPwrSave()) - it is as the device was off. To turn on user must press encoder button for longer than RTCPWRONTIME (rth.h). After that some basic checks are done and startPT() function is called. Menu is handled by tinymenu library which calls handler functions for each menu entry. Timer2 takes care of RTC update, static timers, inactivity timer, power on timer (rtc.c), Timer1 controls LCD backlight (PWM) + dimming (lcd.c), Timer0 - LCD contrast + encoder handling.

Here's video demonstrating how it works (please note this is done on a prototype version with old software):

Here are some pictures of fully assembled phototrigger:


Here are some notes about this design:

  • Press encoder switch for more than 2 seconds to power on device.
  • Encoder, sometimes, is too sensitive (a bit annoying, but one can get used to it).
  • Check power saving option in your camera, when my Pentax K20D camera enters power save mode it will not wake up by remote shutter release.
  • It's better to use „single frame” mode in camera (see below for explanation).
  • When using Pentax K20D in „bulb mode” remember that camera will, after shoot, take dark frame almost as long as the shoot itself (but not exactly the same time, always a little less). You can't turn off this „feature”.
  • For stable battery voltage reading wait until backlight goes off (it causes battery voltage to vary).
  • There might be a bug when backlight is set to 100% and in power off mode backlight will stay off (there's a line that should remove this bug but I'm not 100% sure).
  • If you encounter problems with releasing shutter play with „Shut. rel. time” (increase it), it is how long remote shutter will be short cut. Too low values (<50 ms) may cause that the shutter will not be released due to switch filtering mechanisms in camera, too high values (>150 ms) may shoot several photos if camera is not set to „single frame”.


What you can do using phototrigger:


Files for download:


Please note that I may remove some comments, after time, if they are not valuable.


Wpisz swój komentarz. Można stosować składnię wiki:
elektronika/phototriggeren.txt · ostatnio zmienione: 2014-02-27 02:02 (edycja zewnętrzna)