Introduction. This sketch will detect if the PIR motion sensor switches on, and when it is off long enough to be sure that there is no motion detected anymore.
playground.arduino.cc