PDA

View Full Version : security system using bs2 for school project



Diakka04
06-02-2005, 11:30 AM
I have two sensors running off the stamp. I have checked it with a logic probe to see the highs and lows to the pins. The two sensors work perfectly fine. Then i have a servo moving my camera. The camera is to my VCR which is also to my basic stamp which is run by a relay. I have the servo program, the sensor program and the off and on program for the VCR. I am having trouble with integrating the programs together. I have made an integrated one, but the sensors are taking a long time to go through its program (this program will be at the bottom).
I want the sensor to sense motion and then turn the servo where the motion is coming from, at the same time send a high to the relay to turn on the VCR. But if the two sensors are tripped then it will go into a scan mode. If the sensors are at a constant high then it will say on, but if there's nothing there then it will stay on for two minutes. After the two minutes it will center and turn off the relay.

If you have any questions about this program and other features, then email me at Diakka04@yahoo.com.

I have untell next week to figure and complete this program for my senior project.

The first program is my sensor program:

Specs:
operation voltage 4-12v
operation current 400 micro Amps at 5v
PIR input gain 68dB

'p15 is Relay
'P13 is right Sensor
'p12 is left Sensor
'13 is servo

Main:
IF (IN13 = 1) THEN
GOSUB SensorRight

ELSEIF (IN12 = 1) THEN
GOSUB SensorLeft
ENDIF

SensorRight:

IF (IN13 = 1) THEN
DEBUG IN13 ,"I AM HERE 11111", CR
ELSEIF (IN13 = 0) THEN
DEBUG IN13 ,"I OFF", CR
ENDIF
RETURN

SensorLeft:

IF (IN12 = 1) THEN
DEBUG IN12 ,"I AM HERE 22222", CR
PAUSE 2000
ELSEIF (IN12 = 0) THEN
DEBUG IN12 ,"I OFF", CR

ENDIF
RETURN



The second program that i have is the servo program

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

COUNTER VAR Word

Main: 'Main
FOR COUNTER = 1 TO 150 'left
PULSOUT 14, 1100
PAUSE 20
NEXT



FOR COUNTER = 1 TO 150 'Center
PULSOUT 14, 750
PAUSE 20
NEXT
PAUSE 2000

FOR COUNTER = 1 TO 150 'Right
PULSOUT 14, 200
PAUSE 20
NEXT

FOR COUNTER = 1 TO 150 'Center
PULSOUT 14, 750
PAUSE 20
NEXT
PAUSE 2000

RETURN 'Return to main program

END


My last program is the on and off of the relay to the VCR

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

HIGH 15
PAUSE 1000
LOW 15
PAUSE 500

The integrated program of the one sensor, servo and the relay

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

'first camera program
'================================================= ==========================================
'Variables
'================================================= =========================================
COUNTER VAR Word


'Main program

'================================================= =========================================

Main: 'Main program
IF (IN13 = 1) THEN
GOSUB VCR
GOSUB SensorRight 'If sensor right is high then go sub1
ENDIF

IF (IN13 = 0) THEN
ENDIF
GOTO Main

SensorRight: 'Sensor right
'Go sub1 Sensor right
DEBUG IN13 ,"I AM HERE 11111", CR
PAUSE 200
DEBUG CLS
FOR COUNTER = 1 TO 150
NEXT 'Servo turns right 30 deg
PULSOUT 14, 200
PAUSE 20
IF (IN13 = 1) THEN
GOSUB sensorright
ENDIF
IF (IN13 = 0) THEN
GOSUB center
ENDIF

CENTER:
FOR COUNTER = 1 TO 150 'Center
PULSOUT 14, 750
PAUSE 20
NEXT

GOTO Main


VCR:
HIGH 15
PAUSE 100
LOW 15
RETURN

Lee Harker
06-03-2005, 04:02 AM
Diakka04,
I see a few things that are going to cause you a problem.
In your integrated program, the SensorRight subroutine has a place where the subroutine may be called in recursion. This is not allowed on the Basic Stamp. You will end up crashing the stack.
In the VCR subrouting, you turn on the VCR and then turn it back off right away. I don't imagine that's what you want.
Neither the Center or Sensorright subroutines have a return and this will also crash the stack.
One other thing is not a broken rule but a style warning. You use a variable named counter which is close to the reserved word count. This is legal but someday a typo will cause you a headache. It is a good idea to pick variable names that reduce the possibility of confusion.
Almost forgot. In the sections where you move the servos, you are using a delay of 20 which will probably need some adjustment. The reason is that the program will be in a continuous loop and that will have to figure into the total delay between servo updates. The servo will need refreshed every 20mS.
Hope this helps.