Shop OBEX P1 Docs P2 Docs Learn Events
Cant get this door alarm to work quite right — Parallax Forums

Cant get this door alarm to work quite right

matthew180matthew180 Posts: 7
edited 2010-10-05 16:25 in BASIC Stamp
Ive been trying to build a door alarm using a BS2, a magnet reed switch, a bi-color led, a Solid state relay, a buzzer from Radioshack, and a small toggle switch. I cant get the alarm buzzer to shutoff ever, but the LED will change to red or green depending on what position the switch is in. The toggle switch is supposed to switch the system from armed to disarmed so you can open the door without setting off the buzzer.

my BS2 code looks like:

' {$STAMP BS2}
' {$PBASIC 2.5}

'basic door alarm

LEDRed1 PIN 5
LEDRed0 PIN 4
LEDGrn1 PIN 4
LEDGrn0 PIN 5
sw PIN 1
Door PIN 6
siren PIN 5

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

DO
IF (sw = 0) THEN GOSUB LEDRed ELSE GOSUB Safe
LOOP


LEDRed:

HIGH LEDRed1
LOW LEDRed0
IF (sw = 0) AND (Door = 1)THEN RETURN ELSE IF (sw = 0) AND (Door = 0)THEN GOSUB soundalarm ELSE GOSUB safe

RETURN


Armed:
DO
HIGH LEDRed1
LOW LEDRed0
IF (sw = 0) AND (door = 1)THEN GOSUB checkdoor ELSE IF
(sw = 1)THEN GOSUB Safe ELSE ENDIF
LOOP

checkdoor:
IF (door = 0) THEN GOSUB soundalarm ELSE RETURN


soundalarm:
HIGH siren
IF (sw = 0) THEN GOSUB soundalarm ELSE IF (sw = 1) THEN RETURN

Safe:
HIGH LEDGrn1
LOW LEDGrn0
RETURN

Comments

  • ercoerco Posts: 20,256
    edited 2010-09-30 18:26
    You need a LOW siren somewhere to turn it off. And check your overall logic flow. Your soundalarm subroutine calls itself? And it lacks a solid RETURN; yours is conditional. And you have 2 names each for pins 4 and 5. That would confuse a lesser man!

    One step at a time, mate!
  • matthew180matthew180 Posts: 7
    edited 2010-09-30 18:37
    Im trying to make the soundalarm loop until the switch is changed back so the siren dosent shutoff without the switch being thrown before it returns back to safe, ie the door being closed dosent turn the alarm off
  • matthew180matthew180 Posts: 7
    edited 2010-09-30 18:57
    My code now looks like :

    DO
    IF (sw = 0) THEN GOSUB LEDRed ELSE GOSUB Safe
    LOOP


    LEDRed:

    HIGH LEDRed1
    LOW LEDRed0
    LOW Siren
    IF (sw = 0) AND (Door = 1)THEN RETURN ELSE IF (sw = 0) AND (Door = 0)THEN GOSUB soundalarm ELSE GOSUB safe



    RETURN


    Armed:
    DO
    HIGH LEDRed1
    LOW LEDRed0
    IF (sw = 0) AND (door = 1)THEN GOSUB checkdoor ELSE IF (sw = 1)THEN GOSUB Safe ELSE ENDIF
    LOOP

    checkdoor:
    IF (door = 0) THEN GOSUB soundalarm ELSE RETURN


    soundalarm:
    HIGH siren
    IF (sw = 0) THEN GOSUB soundalarm ELSE IF (sw = 1) THEN RETURN

    Safe:
    HIGH LEDGrn1
    LOW LEDGrn0
    LOW Siren
    RETURN



    and the siren just wails it dosent mater what position any of the switches are in but the LED reacts correctly. The Relay is a Magnecraft 70S2-01-A-03-V rated for 60Vdc 3A maxium and a control voltage of 3-15VDC, and the buzzer is radioshack 273-070. im runing the buzzer off 12V from my transformer and i have a 5V voltage regulator inline for the stamp and LED
  • FranklinFranklin Posts: 4,747
    edited 2010-09-30 19:39
    Perhaps a schematic would help us.
  • ercoerco Posts: 20,256
    edited 2010-09-30 22:47
    Try this:

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}

    'basic door alarm
    '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    'pin1 is toggle switch closed(pin1 high)=alarm off open(pin1 low)=alarm set
    'pin3 goes to siren 0=off 1=on
    'pin4=red LED to ground, indicates alarm off
    'pin5=green LED to ground, indicates alarm on
    'pin6= door switch 0=door open 1= door closed

    main:IF IN1=1 THEN LOW 3:HIGH 4:LOW 5:GOTO main' if switch is closed, LEDs show safe mode, siren off
    IF IN1=0 THEN LOW 4:HIGH 5' LEDs show alarm on
    IF IN6=0 THEN HIGH 3' sound alarm if door open
    GOTO main' loop back
  • matthew180matthew180 Posts: 7
    edited 2010-10-01 17:00
    I tryed loading that and the alarm still just goes off regardless of where both switches are. could the pin on the stamp that controls the relay be bad?
  • ercoerco Posts: 20,256
    edited 2010-10-01 18:00
    Hard to say, it all depends on how you hooked it up. It's a 5V siren, correct? Did you hook it up to pin 3, per my program comments? You originally had it hooked up to pin 5 along with an LED. Are you driving it directly or through a relay? How much current does it draw?
  • matthew180matthew180 Posts: 7
    edited 2010-10-01 19:47
    The siren is a 12V radioshack 2 tone siren #273-070 and I am using a Magnecraft 70S2-01-A-03-V solidstate relay to drive it. I hooked it up per your program and it just sat there and wailed
  • ercoerco Posts: 20,256
    edited 2010-10-01 22:26
    Sure you have the relay hooked up correctly to pin3? This program will test pulse your alarm once each second:

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}

    a:toggle 3: pause 1000:goto a
  • bill190bill190 Posts: 769
    edited 2010-10-01 23:20
    matthew180 wrote: »
    The siren is a 12V radioshack 2 tone siren #273-070 and I am using a Magnecraft 70S2-01-A-03-V solidstate relay to drive it. I hooked it up per your program and it just sat there and wailed

    I would suggest using a mechanical relay instead. Then you can "see" inside the relay and see what is going on.

    Be sure to install a backwards or "flyback" diode on the coil as discussed in the following...
    http://www.physics.unlv.edu/~bill/PHYS483/relay.pdf
  • ercoerco Posts: 20,256
    edited 2010-10-01 23:46
    Good call, bill190. Radio Shack has a 5V reed relay that a Stamp can drive directly, and a flyback diode is in order. See http://www.radioshack.com/product/index.jsp?productId=2062478
  • matthew180matthew180 Posts: 7
    edited 2010-10-02 10:59
    allright I gota head out to radioshack to get the relay and diode I dont have them siting around, ive got alot of stuff but none of what I need >.>
  • FranklinFranklin Posts: 4,747
    edited 2010-10-02 17:46
    ive got alot of stuff but none of what I need
    Yeah, isn't that the way it always works? NEW TOOLS !!!
  • AmaralAmaral Posts: 176
    edited 2010-10-04 12:34
    The routine "armed" is never called, but that is not the cause of your problems.
    I'm wondering what kind of switch are you using, and what are you using to minimize de-bonce this.

    Amaral.
  • ercoerco Posts: 20,256
    edited 2010-10-04 13:12
    matthew: just hook up an LED in place of your relay/alarm and get it working properly, then you can sort out your relay issue.
  • ercoerco Posts: 20,256
    edited 2010-10-05 10:13
    matthew: One other possible issue is how you have your sensor switches hooked up to your Stamp. The Stamp IO pins must always be forced high or low, they can never be floating, or simply disconnected from the circuit. That is an unstable condition that can cause false triggering. Are you using pullup or pulldown resistors? If not, that's probably your problem.
  • matthew180matthew180 Posts: 7
    edited 2010-10-05 16:25
    I have pulldown resistors on everything but the pin going to the relay i just got the relay today too I will test it in a min

    @Amaral I have a SPDT mini leverswitch that gets pressed when I put a pin in to a hole in the case its a modified radioshack 275-0016
Sign In or Register to comment.