CHDK Motion Detect Plus Script

By , February 26, 2012 11:19 pm

Version 0.3.1 Released Sept 16, 2012

This is a screen capture of the CHDK Motion Detect Plus script in action.

This is a screen capture of the CHDK Motion Detect Plus script in action.

I created a CHDK motion detection script called "Motion Detect Plus" to take repetitive shots with motion detection.

This Motion Detect Plus script adds a repetitive shot feature to the standard CHDK "motion.lua" script. This is useful for compiling a motion time-lapse sequence using motion detection to trigger the photos instead of a traditional intervalometer.

The script is called motionp.lua and should work with most cameras that support CHDK.

Tip: If the camera takes photos continuously with the Motion Detect Plus script try setting the motion threshold to 36 (the Dawn/Dusk mode) for a reduced motion sensitivity.

Download

You can download the CHDK Motion Detect Plus script here.

Sample Motion Detect Images

Black-capped Chickadee

Black-capped Chickadee

American Robin

American Robin

Script Controls

There are several settings that can be set in the CHDK Script preferences:

The version 0.2 upgrade adds a "Motion Threshold" parameter that lets you control the responsiveness of the motion detection feature. If the camera takes photos continuously increase the "Motion Threshold" setting for a reduced motion detection response.

Here are several typical motion threshold levels:

12=Sun 24=Cloudy 36=Dawn/Dusk

You can set a start delay in minutes and seconds. This gives you time to set up your shot before the motion detection is enabled.

The "Number of Shots" variable takes a burst of photos during a motion detection event. This gives you a better chance of catching interesting photos when the motion detection trigger is set off.

The hollow boxes onscreen are the detection grid. You can choose to show or hide the detection grid.

You can set up a detection grid by defining the number of Grid Columns and Grid Rows. Once the grid is defined you can enable specific cells in the detection grid by specifying the Start Column / End Column and Start Row / End Row values.

The region value controls the motion detection masking zones. The region value can then be set to either:

0 = No (disable regions)

1 = In (The area inside the start / end region is the detection zone)

2 = Out (The area outside the start / end region is the detection zone).

Setting up the motionP.lua Script Settings

Setting up the motionP.lua Script Settings

Version History

Version 0.3.1
Created Sept 16, 2012
Changed the zones variable to avoid a naming conflict.
Added a "Number of Shots" variable that takes a burst of photos during a motion detection event.

Version 0.3
Created August 20, 2012
Improved the motion threshold settings.

Version 0.2
Created June 25, 2012
Added a "Motion Threshold" parameter

Version 0.1
Created on Feb 26, 2012
Initial Release of Motion Detect Plus

Script Installation

Step 1. Copy the motionp.lua script to the CHDK scripts folder on your SD memory card.

Step 2. Start CHDK and from the ALT Menu open the "Scripting Parameters" Menu. In the script window select the "Load Script from File..." menu option. Then in the "Select Script File" window select the MOTIONP.LUA script and press the Func. Set button to load the script.

Selecting the MOTIONP.LUA CHDK Script

Selecting the MOTIONP.LUA CHDK Script

Step 3. Set the script parameters for Motion Detect Plus and define your motion detection grid size, and masking region settings.

Step 4. Exit the CHDK Menus and start the Motion Detect Plus script by pressing the shutter button when the text ALT is displayed on screen. If you enabled a Start Delay period the camera will play a short beeping noise to indicate when the start delay period is over.

The grey rectangles on the LCD screen show the active motion detection regions. If motion occurs within one of the selected rectangles a new photo will be taken.

The script will display a counter showing how many photos have been taken since the script was started.

The Motion Detect Plus photo counter looks like this:

3 Shots Taken

Motion Detect Plus <ALT>

If the script takes photos nonstop you should adjust the motion threshold parameter in the CHDK Alt Menu Script window. A motion threshold value of 12 seems to work for sunny days and a motion threshold value of 24 works well for cloudy or overcast days.

Step 5. You can stop the script at any point by pressing the shutter button.

Note: There appears to be an issue where the motion detection function doesn't reset for the next photo unless the image review mode is disabled. To disable the image review feature, open the main Canon menu by pressing the menu button on your camera. Scroll down to the option labeled Review and set it to Off. It is also important to set the camera to single shot mode.

Turn the review mode to OFF.

Turn the review mode to OFF.

Controlling the Detection Regions

The Motion Detect Plus script allows you to create any type of grid layout you desire in the scripting parameters window. Non-uniform grids layouts are also supported such as a 12x10 layout.

In this demonstration I will present a few of the more common motion detection grid arrangements possible with the Motion Detect Plus script. For this example I am using a 3x3 grid layout with 3 columns, and 3 rows.

An illustration of motion detection regions.

An illustration of motion detection regions.

To enable every block on the grid

Region:0 (No)

This will set the whole screen to be active for motion detection.

In this illustration all of the grid regions are enabled.

In this illustration all of the grid regions are enabled.

To enable just the center block

Region: In

Start Column: 2

End Column: 2

Start Row: 2

End Row: 2

In this illustration the center region is enabled.

In this illustration the center region is enabled.

To enable the center and center-right blocks choose

Region: In

Start Column: 2

End Column: 3

Start Row: 2

End Row: 2

In this illustration the center and center-right regions are enabled.

In this illustration the center and center-right regions are enabled.

To enable a lower corner 2x2 block section choose

Region: In

Start Column: 2

End Column: 3

Start Row: 2

End Row: 3

In this illustration a square region on the lower right is enabled.

In this illustration a square region on the lower right is enabled.

To enable a vertical column on the right side choose

Region: In

Start Column: 3

End Column: 3

Start Row: 1

End Row: 3

In this illustration a vertical column region on the right side is enabled.

In this illustration a vertical column region on the right side is enabled.

To enable the top two rows choose

Region: In

Start Column: 1

End Column: 3

Start Row: 1

End Row: 2

In this illustration a double rows region at the top is enabled.

In this illustration a double rows region at the top is enabled.

To enable a vertical column on the left side choose

Region: In

Start Column: 1

End Column: 1

Start Row: 1

End Row: 3

In this illustration a vertical column region on the left is enabled.

In this illustration a vertical column region on the left is enabled.

Bonus Tip

With the region set to 2 (Out) the motion detection script will exclude motion from the active grid box. This allows you to define the unselected areas as the place where motion will be detected.

Print Friendly

52 Responses to “CHDK Motion Detect Plus Script”

  1. Andrew B says:

    I have tried without success to access the code from my memory card. I have a Canon SX40HS. I take a photo, I then go to the play, displaying the photo, I turn on my camera then press function set and disp at the same time, nothing happens.

    Anybody know what I am doing wrong?

  2. Andrew Hazelden says:

    You need to have CHDK installed and loaded before you are able to use the Motion Detect Plus Script. Once CHDK is running on your camera you can then load the Motion Detect Plus Script in the CHDK ALT menu using the Scripting Parameters window.

    A handy way to install CHDK on your memory card so it boots automatically is to use the Cardtricks utility:
    http://chdk.wikia.com/wiki/CardTricks

    To open the CHDK ALT menus you need to press the shortcut button on your Canon SX40HS camera. For more details on how to use CHDK with your specific camera model look in the readme.txt file that came with your copy of CHDK.

    Regards,
    Andrew Hazelden

  3. Jon says:

    I have just installed CHDK on my SX40HS, and run your script. Once motion is detected it seems to continue to take shots. Is there a way to limit the number of shots or time period please?
    Ideally I would like it to detect a bird landing on a rock, take shots while it is perched, then stop and reset when the bird flies off (and be ready for the next bird landing)

    Is this possible please?

  4. Andrew Hazelden says:

    Hi Jon.

    I did some testing this morning with the CHDK Motion Detect Plus script.

    If the image review feature is turned on there appears to be an issue where the script takes photos continuously after the first motion detect trigger. On my camera a simple fix for this problem is to turn off the image review feature in the Canon menu. This will result in the camera taking a single photo when it detects motion.

    Regards,
    Andrew Hazelden

  5. Jon says:

    Hi Andrew

    That seems to have solved the problem - thanks.
    Two further questions though please;

    1) Is it possible to use the script with high speed burst mode (8fps)?
    2) I tested the script this afternoon, and when I returned to the camera after 30 minutes it had powered down (with the lens still out)I have the power save option set to off, but maybe you can suggest what I may have done wrong.

    Thanks again

    Jon

  6. Andrew Hazelden says:

    Hi Jon.

    1. It would be possible to modify the LUA script to take a series of photos once a motion event is detected.

    2. If the camera is off with the lens out, either your camera battery died or CHDK locked up. Eject the battery and put it back in to reboot the camera.

    This morning I set up my Canon Powershot camera for an all day motion detection test. To power the camera I'm using an ACK-DC10 external power supply module with a dummy battery module.

  7. Frojnd says:

    Hi there. Thanx for your script and your time/work Andrew Hazelden.

    Unfortunately this script does not work correctly on ixus 220 aka elph 300hs.

    "There appears to be an issue where the motion detection function doesn't reset for the next photo unless the image review mode is disabled. To disable the image review feature, open the main Canon menu by pressing the menu button on your camera. Scroll down to the option labeled Review and set it to Off."

    Even if I set review to OFF. The problem persists.

    I have the latest stable build: ixus220_elph300hs-100c-1.0.0-1892-full_ALPHA

  8. Andrew Hazelden says:

    Hi Frojnd.

    Thanks for your message.

    I'm interested in hearing more about the Motion Detection Plus script issue on the Canon IXUS 220 camera. Could you describe what happens when you try to run the script? Does the software get stuck in a continuous photo taking loop?

    Regards,
    Andrew

  9. Hi Andrew!
    My problem is similar to FrojndĀ“s.
    I have the canon sx40 with the last chdk and the camera keeps shooting until shooter pressed. Review is off, AF beam is off.

    Thank you.

  10. Andrew Hazelden says:

    Hi Frojnd.

    It appears the issue you are experiencing is due to the script's motion detection "trigger sensitivity" threshold. I have an updated script that has a lower default sensitivity and provides control over the parameter.

    After I run a camera test on my lawn for a day to make sure it works I will post the improved script.

  11. Andrew Hazelden says:

    Hi Armando & Frojnd.

    I have posted a new version of the Motion Detect Plus script. Hopefully this update will work better on the Canon Powershot sx40 and IXUS 220 cameras.

  12. Thank you very much, Andrew!

  13. Todd Higgins says:

    Thanks for the great script love it. How can I mod the script to take multi-shots when motion is detected? Thanks.

  14. Andrew Hazelden says:

    Hi Todd.

    I will add a multi-shot feature to the next version of the Motion Detect Plus script. It might be a few days before I get around to it.

    Regards,
    Andrew

  15. Tom Jensen says:

    Dear Andrew

    I have downloaded you script Motionp.lua (Thank you for making that possible).
    My camera is a Cannon sx40hs.
    I have the same problem like Armando, my camera keeps on shooting after the first picture until shutter is pressed.
    Review is set to Off.
    AF beam is set to Off.
    Can you help ?

    Best regards:
    Tom Jensen.

  16. Andrew Hazelden says:

    Hi Tom.

    Try increasing the Motion threshold value. This will reduce the camera's sensitivity and stop the camera from taking continuous photos. Open the CHDK scripting parameters window and adjust the script's Motion Threshold value to a higher number. You could try a higher value like 36 to see if it helps.

    Regards,
    Andrew

  17. Tom Jensen says:

    Dear Andrew.

    Thank you for your quick reply. I went up to 40 but it did not help. Any idea of what else I can try?

    Best regards:
    Tom Jensen.

  18. Andrew Hazelden says:

    Tom,

    Try setting your camera from continuous mode to single shot mode. If that doesn't help you could try setting the CHDK options back to their defaults by going to the CHDK Miscellaneous Stuff menu and selecting Reset Options to Default...

  19. Tom Jensen says:

    Dear Andrew.

    Thank you very much.That solved all my problems.

    Best regards:
    Tom Jensen.

  20. Rich says:

    I'm still having trouble with the lag of the motion detection. When I tested it by waving my hand in front, it didn't take the picture until well after my hand had already passed. I have turned off all the AF stuff as well as the picture review. Did I miss something?

  21. Andrew Hazelden says:

    Hi Rich.

    It might be possible to speed up the Motion Detect Plus script's responsiveness using the CHDK lightning detection scripts as reference. There are a few parameters that have to be balanced so a motion detection script doesn't go in a continuous photo taking cycle.

    Regards,
    Andrew

  22. Luis says:

    Hi, I have a Canon 720IS camera I have installed the script but I have a problem. When the camera detect motion. The camera donĀ“t make the photo, it takes about ten seconds. My question is The camera can to make the photo when detect motion? In this moment no after ten seconds.

    Thanks
    Luis

  23. Matthew H says:

    I have downloaded you script Motionp.lua
    Thank you for publishing the script.
    My camera is a Cannon PowerShot S2 IS running chdk "s2is-100f-1.1.0-2079-full"
    I have a similar problem like Armando. My camera keeps on shooting after the first picture until shutter is pressed. This would be indoors.
    Review is set to Off.
    AF is set to single
    AF beam is set to Off.
    I've tinkered with the Motion threshold from 12, 24, 36 and even 40.
    What am I missing?

    Thanks,
    Matthew H

  24. Andrew Hazelden says:

    Hi Mathew.

    I updated the Motion Detect Plus script to version 0.3. This should fix the motion threshold issue.

    Regards,
    Andrew

  25. Paul H says:

    I was having problems with the script not working with my S3 powershot - multiple shots taken once motion occurred. Didn't seem to matter what threshold I used - once triggered, wouldn't stop taking shots. I made a change to the script which has fixed the problem - change the variable zones to mot. Prior to doing this, I added a line in the script to display the value of zones to see what it was doing when motion detected, and it would return a number based on how many zones had detected motion, so would always remain >0.

    To fix, open the script in notepad and change all instances of the word zones to mot in the lower part of the program.

    Anyway, an easy fix which may work for others having trouble getting it to work currently on their cameras. What I don't understand is why the script works on some but not all cameras.

    Regards,
    Paul

  26. Andrew Hazelden says:

    Hi Paul.

    Thanks for your comment and tip. Would you be able to send me a copy of your revised script so I can test the changes on my Canon PowerShot SD780IS? My email address is andrewhazelden@gmail.com

    Regards,
    Andrew Hazelden

  27. Bryan says:

    There is absolutely no way to make this work on the ELPH300 HS...I have tried EVERY possible combination of setting, camera setting, etc. No matter what, the camera is ALWAYS stuck in a continuous loop.

  28. Paul says:

    Hi Bryan,
    Try adding sleep(250) as a new line after the line print(q .. " Shots Taken" ) near the end of the program. You may also need to increase the value a bit if it still false triggers - perhaps sleep(500) or more, but 250 fixed mine. My post above seemed to work for some scenes, but not for others. Since adding the sleep line, I have not had any further issues with false triggering after initial motion detection.
    Regards,
    Paul

  29. Jasen says:

    I played around with this on my S3 IS today and FINALLY got it to stop continuously shooting. The trick: Put a sleep() after the shoot().

    I changed my script around to take in an interval - param e. I then put a sleep() in for the same amount of time after the shoot(). e is expressed in 1/4 seconds. (e = e*250)

    I don't know if it needs to sleep that long. I don't know if there's a constant value that would work. But as soon as I put the sleep in things settled down. I was able to use very low threshold values with no problem.

  30. Andrew Hazelden says:

    Hi. I updated the Motion Detect Plus script to version 0.3.1. This build includes the suggestions from Paul H on how to reduce the continuous photo issue and adds a "Number of Shots" attribute that Todd Higgins was interested in.
    Regards,
    Andrew Hazelden

  31. Andy says:

    Hi, I'm still getting the continuous shot issue. Mine is an SX40 HS and no matter what I do the loop continues.

    All AF settings off, I've had the motion threshold up to 70 still the same.

    Any ideas as to what this may be?

  32. Andrew Hazelden says:

    Hi Andy.

    Try turning off image review in the Canon menu.

    Also, could you try setting your SX40 HS camera to take the photos in single shot mode?

  33. sama says:

    Try set the script shoot delay (.1s) to 5 or upwards.

  34. Bill Balharry says:

    Hi Andrew,

    Your Motion Detect Plus works great on my sx40hs, thank you very much. I had previously started to download another before realizing it was uploaded in 2008! I liked the easily variable sensitivity, and the grid with active/inactive squares, and the shot count on the scree. On one day only the count continued to display; albeit only for a fraction of a second; throughout all of the afternoon whilst taking over 70 normal manual photo's, which I liked, however I have tried but I have not been able to repeat this effect.

    Whilst using your script on my sx40 I tried it with 'Movie Digest' enabled, and most of the time it worked well, although sometimes freezing CHDK and shutting the camera down with lens extended. I have not yet determined the consistent differences between settings for those shots that continued to detect motion and take a photo and a 'Movie Digest', and those which froze CHDK.

    'Movie Digest' on the sx40 is an interesting mode which saves a short film starting 2 to 4 seconds BEFORE the 'take a photo' button is pressed!! AND happily responds also to a CHDK simulated 'button pressed'. Unfortunately the film saved is only 640 x 480, but when coupled with your Motion Detection script it ALMOST GUARANTEES a film of the event which triggered the photo, be it a lightning flash or something else very fast!

    I don't think 'Movie Digest' is much good for its stated purpose; an optional brief audio recording filed with the photo would be much better; but used as an adjunct to motion-detected image capture it is VERY useful.

    Are you aware of that excellent shortcut someone (sorry, don't have his name) just highlighted?: a half-press of the 'take a pic' button plus a left press of the rocker dial takes several cameras; including the sx30 and the sx40; straight into 'Manual Focus' mode and focused where the Auto mode set it!

    Thanks again.
    Bill

  35. Andrew Hazelden says:

    Hi Bill.

    I'm happy to hear the Motion Detect Plus script works on your camera. I haven't had a chance to personally use a Canon Powershot sx40 yet but the new Movie Digest feature sounds interesting.

    Regards,
    Andrew

  36. Andy Taylor says:

    Andrew, I am trying to run the Motion Detect Plus script on an IXUS 100, but when I try to run the script, it does not start up the camera. Any ideas ?
    Andy

  37. Andrew Hazelden says:

    Hi Andy.

    What build of CHDK are you running? After you load the script in the CHDK Script menu you have to click the camera's shutter button to start running the Motion Detect Plus script.

  38. Andy Taylor says:

    Hi Andrew, thanks for getting back to me, I am running the latest version of CHDK, ixus100_sd780-100c-1.1.0-2447-full_BETA.zip, and the latest Motion Detect Plus script.

    I start up CHDK, and have the motion detect script as autostart. It comes up and says it is about to start before you press the shutter button!

    Should I switch off the autostart? I see from reading your blog that you have the same camera, albeit an American version.

    Thanks
    Andy

  39. Andy Taylor says:

    Hi, just tried it with autostart switched off, and I can now press the shutter release to power it up. When I press the Alt button, I get Motion Detect Plus in the bottom left corner, then when I press the shutter release button, it displays the 3 seconds to start message, then the "Starting" message, then the LCD switches off, and it appears dead, but with the lens out and open!

    Andy

  40. Andrew Hazelden says:

    Hi Andy.

    The Motion Detect Plus script expects the camera to be in photo mode to work. Since the Ixus 100 starts in playback mode that is what causes the error.

    In the next version of the script I will look into adding code to verify the camera is in photo mode before starting.

    Regards,
    Andrew

  41. Andy Taylor says:

    Hi, presumably you have the same issue on your SD780. How do you get around it on there?

    Andy

  42. Andrew Hazelden says:

    Hi Andy.

    I installed CHDK on the camera's SD card and set it to boot when the card is in 'locked mode'.

    I start my Canon SD780IS camera in review mode and then switch the camera over to photo mode. At this point I enable the ALT mode by tapping the DISP button quickly. With the ALT mode text onscreen I start the Motion Detect script by pressing the shutter button.

  43. Andy Taylor says:

    Sorry if I am being thick here, but would that not stop the card from being usable if it is locked, or does CHDK get round that?

    Should I try and make mine bootable?

    Andy

  44. Andrew Hazelden says:

    Andy,

    CHDK uses the lock state switch on the SD card to enable/disable booting. In this mode the camera can still write to the SD card.

    The CHDK wiki has a good page on enabling booting on your SD card:
    http://chdk.wikia.com/wiki/Prepare_your_SD_card

  45. Norman says:

    I am using an SX260 HS with your Motion Plus script. I have turned off focus assist beam, auto focus continuous, autostart is off, continuous shooting is off, I am using CHDK build 2542. My camera shoots continuously, until I stop it and never fires with motion, just when I push the button. Other people are having success with your script, so I know it works. Shouldn't it also work with mine?

  46. Andrew Hazelden says:

    Hi Norman.

    Could you try changing the sleep(250) setting on line 167 to sleep(1000). This will give your Powershot SX260HS camera time to pause between each motion detect cycle.

  47. Norman says:

    Thanks for the suggestion, Andrew, but it did not work. I changed the sleep setting to 1000 and it did the same thing, shot 5 exposures and waited, then started on another set of 5 when I approached the camera to interrupt the script.

  48. Joel Popkin says:

    Hi Andrew,

    Thanks so much for your motion detector. Amazing that this can work in a point and shoot. I have a Wingscapes Bird Cam, which is a bit of a disappointment, and I'm very exciting about potentially getting bird pictures with your program. I'm using an SD1200 IS.

    Please pardon the naive mix of questions -- I'm a total newbie at this and an old guy, making it even worse. Here goes:
    1. Under Script, I don't know what number to use for parameters
    2. Under Extra Photo Operatons, I don't know how what to set for disable override, autobracket, and value factor.
    3. Under Misc Stuff, I don't know what to set Disable LCD.

    It gets worse. For the camera itself, does auto vs. program mode make a difference?

    No matter what I set the threshold at, the pictures take several seconds to fire and the actual motion may take several seconds or more to start the sequence.

    The camera shuts down and no longer senses about 45 seconds after the last picture. I haven't yet gotten an external power supply, so maybe that will make the difference?

    Finally, when you make a parameter change, is there a save function? Sometimes the changes are there the next time I work on it, while sometimes the changes have gone away.

    Again, my sincere apologies for this huge list of questions, and I thank you again for your program and what seems to be your infinite patience. I am working on a newbie cheat sheet that I'll send you for using for inquiries from any similar old strugglers such as myself as soon as I fine tune things a bit.

    Best, Joel

  49. Joel Popkin says:

    Hi Andrew,
    Got some of the above straightened out. The prolonged time taken between shots was due to inadvertent setting of RAW imaging, which causes a long delay between shots with the SD1200. Also, I now have an external power source and have built a housing using a Plano dry box, and that is working well.

    Still need some help with the rest of the questions, although it seems to be working much better for the most part without knowing what I'm doing...

    Thanks for your help.

    Joel

  50. Joel Popkin says:

    Andrew,

    Should have added that with the external power supply, the camera no longer shuts down until I turn it off.

    Thanks again. Joel

  51. Andrew Hazelden says:

    Hi Joel.

    I'm glad to hear your camera is working better with the motion detect script.

    If you would like to read more about shutter speed overrides you can check out this blog post CHDK Shutter Speed Overrides Explained.

    If you are using the same photo overrides between multiple power ON/OFF cycles you may want to turn off the clear overrides @ start option in the Extra Photo Operations menu.

    I would suggest you lock the camera into a the program mode. It is a good idea to select a white balance setting like sun, cloud, tungsten, etc... so the white balance doesn't change during the duration of your image recording session.

    The easiest way to disable the LCD is to plug in the composite video output cable for your camera. This will tell the camera to turn off the LCD display. (You don't have to plug the other end of the cord into anything.)

    Regards,
    Andrew

  52. Verne Nelson says:

    I have tried both your program (motionp) and the one it is based on (motion) on a Canon S95 in manual mode with manual focus for hummingbirds coming to my feeder.
    "motion" will take the shot, only one of course. "motionp" will also take the shot(s), however if the subject does not stay in the AF frame it refocuses the lens to objects in the background rather than holding the MF. I tested this by first focusing close on my hand and then triggering each of the programs by moving my hand through and out of the grid field. "motion" holds the BG in a blur, but "motionp" refocuses to the BG.
    I see that all your a-z are the same as the original program. What could be doing this?