Cant get this door alarm to work quite right
matthew180
Posts: 7
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
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
One step at a time, mate!
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
' {$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
' {$STAMP BS2}
' {$PBASIC 2.5}
a:toggle 3: pause 1000:goto a
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
I'm wondering what kind of switch are you using, and what are you using to minimize de-bonce this.
Amaral.
@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