Older newbie needs helps wih alarm code

Bob Champagne

New Member
After reading countless pages on this wonderful forum and asking for help, I have completed several simple projects. But now I stumble on a trivial problem with a solution I think so simple that I can't see it... I'm making an alarm system for a cottage on a remote location. Among other things there will be a magnetic sensor connected to a door. When the door is opened the NC circuit is broken and a signal is send to the Picaxe that is connected to a relay and a siren. After a couple of minutes the siren will shut off. Now if the door is left open for days no more siren and that's OK.
But if the door is closed and the NC circuit is reactivated, I want the siren to sound again if the door is reopened. For that part, I have tried every combinations of if and then and do and loop I could think off with no success. The answer is probably obvious for the majority of you but my old brains can't figure it out. So if someone could steer me in the right direction, I would greatly appreciate. Thanks in advance, Bob.
Her's the closest I came:
Code:
start1:
  if pin3=0 then HIGH 2
  endif
  pause 5000
  LOW 2
  goto flash
  
flash:
  do UNTIL pin3=1
  LOOP
  goto start1
 
Last edited:

lbenson

Senior Member
Is pin3 "floating"--that is, not pulled down (in this case) when the door is open? If it is, then try putting a 10K resistor from pin3 to ground to assure that it just doesn't float high when the door is opened.
 

lbenson

Senior Member
And try this (there will be an initial "armed" beep if the door starts off open:
Code:
start1:
  do while pin3 = 1 : loop
  HIGH 2
  pause 5000
  LOW 2
  do while pin3 = 0 : loop
  goto start1
 

hippy

Technical Support
Staff member
Be careful with a "Start1:" label (and similar) if using a PICAXE-M2.

That starts a separate task and, without a "Start0:", you will end up with two tasks executing the same code which can cause very odd things to happen.
 

Bob Champagne

New Member
And try this (there will be an initial "armed" beep if the door starts off open:
Code:
start1:
  do while pin3 = 1 : loop
  HIGH 2
  pause 5000
  LOW 2
  do while pin3 = 0 : loop
  goto start1
Thank you very much for the fast answer. That is 100% what I tried in vain to get right. Thanks again...Bob
 

Bob Champagne

New Member
Be careful with a "Start1:" label (and similar) if using a PICAXE-M2.

That starts a separate task and, without a "Start0:", you will end up with two tasks executing the same code which can cause very odd things to happen.
This forum amazes me. Fast answer right on the money. That was part of the code, I have a start0 routine. Thanks again...Bob.
 
Top