Rob Zwetsloot over at Linux User has done a nice tutorial with code listing that shows you how to do motion detection with the camera module. It takes a picture, stores it in a stream and then captures another image, comparing the two on the fly to detect changes. Read all about it here.