Motion/Lightning Detect[]

Written for/on: Canon A640
Also works on: Other Canon AXXX (Not tested), Canon A720 (tested), Canon A710 (tested), Canon PowerShot S3 (tested), Canon A540 (tested), A620 (tested), Canon A610 (tested)
Doesn't work on: Canon A650IS - try UBASIC/Scripts:_Multipurpose_Motion_Detection

Motion/Lightning Detect by Johan Van Barel (

The purpose of this script is to take pictures when motion is detected. The screen will be divided into a number of Rows and Columns. The Treshold value determines the treshold for detection. Recommended experimental values are 10=Lightning, 12=Sunshine, 24=Cloudy, 36=Dawn/Dusk. Motion can be detected in the following Modes: 0=U, 1=Y, 2=V, 3=R, 4=G, 5=B. The Pixel Blocksize determines how many pixels are seen as one block. Smaller blocks are more accurate but detection will be slower.

An important parameter is the Triggering Delay value. A value of 0 is meant for ultrafast motion detection (fi. lightning). In this mode, the shoot-button will be pressed half before detection is started, so the actual shooting is very fast. Disadvantage is that (in Auto-mode) the focus/aperture/shutter will be fixed before the moving object is detected (except when using all manual settings like manual focus/aperture/shutter). If you choose a value > 0, the shoot-button will not be half-pressed before detection, so the moving object's focus/aperture/shutter will be set after motion is detected. Important: you should be careful that the value is big enough to avoid shoot-looping after first detection. A value of at least 16 (=1.6 secs) will be ok. If you want to motion-detect for longer periods, you should disable the power-save options of your camera, so that your camera will not power-off after a certain time.

ps. for long detection periods you should disable the Power Saving options of your camera. This can be done in the <ALT> menu. In the Miscellaneous Stuff menu item set the Disable LCD Off value to Script, so the display won't turn off while in <ALT> mode or while a script is running.

Documentation/Help (save as MotionDetect.txt" file to your /CHDK/SCRIPTS/ folder)

Select P, Tv, Av, M or C mode on your Canon A640.


  • Number Of Columns (Default=6)
  • Number Of Rows (Default=4)
  • Treshold (0-255) (Default=24) recommended values: 10=Lightning, 12=Sunshine, 24=Cloudy, 36=Dawn/Dusk
  • Comparison Interval (mSec) (Default=1)
  • Triggering Delay (.1 Sec) (Default=0) recommended values: 0=Ul