copied motion detector from http://www.raspberrypi.org/phpBB3/viewtopic.php?t=45235&p=362909