Monitoring an intermittent input


New Member
Hi, I have a PIR sensor that provides an intermittent output (goes on and off) when detecting a target. When it goes high the first time, I want to turn a video camera on. I then want to keep the camera on for as long as I am getting that intermittent signal. The time between the intermittent pules (the input going high) might be up to 10 seconds. Then I want to camera to stay on for 40 seconds after the last detection event and then turn off.

So I can work out some basics for this but I can't really nail it!!! I'm sure it's not an uncommon routine, but I can't find an example. Any help would be greatly appreciated.



Senior Member
You are correct. It is not an uncommon routine. I think it would be best done using a background timer. M2s do it simply with a system variable called Time, which increments every second. Refer also to EnableTime and DisableTime commands. Obviously, it can also be done with an X2 PICAXE but the timer needs to be configured (one extra command).

Your main loop basically needs to do two things:
  1. Checks to sensor. When active, it sets the camera output to 'on', and resets the timer value to 0 and then enables the timer. While the sensor is on (active), the PICAXE will continually repeat this action. When the sensor input is off, it stops resetting the timer, allowing the timer to increment upwards.
  2. Checks the Time variable. When equal to 40, it disables the timer and sets the output to 'off'.


Senior Member
The following code is taken directly from one of my applications, although I have removed a lot of stuff that is unrelated to your needs. Of course, you will need to add symbols for the labels that I have used. For symbols, I use prefix i for input pin, o for output pin, c for constant value.

Rich (BB code):
   If iPushButton = cPressed Then   'A key press 
      High oPowerRelay              'Turn power on
      Time = 0                      'Reset timer
      Enabletime                    'Enable timer
   If Time = cPwrOffTime Then       'Timer period has expired
      Low oPowerRelay               'Turn power off
      Disabletime                   'Disable timer