Total noob needs help with programm
Wallydrag
Posts: 16
Okay guys, I need a lot of help since I really know nothing.
I'm wanting to use a BASIC Stamp 1 Carrier Board (which means programming a BASIC Stamp 1 Module I think) to control a small DC motor. I'm also wanting to use a parallax PIR sensor to activate the motor.
It doesn't seem like that hard of a thing to accomplish, I just don't really know how to do it.
I'm wanting it to do this:
When the PIR sensor senses movement it activates the motor to turn for 0.5 seconds then stop, pause for 5 seconds, then revers polarity and turn the other way for 0.5 seconds, then pause for 30 seconds and reset.
I also need to control how fast the motor spins but I think I do that with resistors (though I could be wrong).
Any help at all would be very, very appreciated! Thanks!
I'm wanting to use a BASIC Stamp 1 Carrier Board (which means programming a BASIC Stamp 1 Module I think) to control a small DC motor. I'm also wanting to use a parallax PIR sensor to activate the motor.
It doesn't seem like that hard of a thing to accomplish, I just don't really know how to do it.
I'm wanting it to do this:
When the PIR sensor senses movement it activates the motor to turn for 0.5 seconds then stop, pause for 5 seconds, then revers polarity and turn the other way for 0.5 seconds, then pause for 30 seconds and reset.
I also need to control how fast the motor spins but I think I do that with resistors (though I could be wrong).
Any help at all would be very, very appreciated! Thanks!
Comments
Brad
http://www.efx-tek.com/topics/prop-1.html
Hope this helps!
What I'm trying to make happen is that when the PIR senses a motion it will send a signal to Pin 0. When that signal should trigger "Motor:" to run. I've also tried to make it so that once the stamp recognizes that first signal, it won't recognize any more for 60 seconds. I guess I should make it that once it gets the first signal it reverses to output for 60 seconds the back to input until it gets another signal again.
My real trouble is that when I check the syntax it highlights the "THEN" and says Error: Expected an operator. Thanks for the help.
' {$STAMP BS1}
' {$PBASIC 1.0}
SYMBOL PIR = PIN0
LET DIRS = %00001110
Main:
IF PIR THEN Motor
PAUSE 60000
GOTO Main
Motor:
HIGH PIN1
LOW PIN2
HIGH PIN3
PAUSE 500
LOW PIN1
LOW PIN2
HIGH PIN3
PAUSE 5000
LOW PIN1
HIGH PIN2
HIGH PIN3
PAUSE 500
LOW PIN1
LOW PIN2
HIGH PIN3
NAP 30000
GOTO Main
IF PIR = 1 THEN Motor for example. Look at·IF using the Basic Stamp Editor help it explains it.
Brad
Hopefully what this program will do is keep checking PIN 0 until it sense a signal being sent from the PIR. When the input sense a signal it will reverse PIN 0 to output so that even if the PIR keeps sending signals it won't see them. The motor will run through it's routine then hang out for 54 seconds (for a total of 60 seconds from start to finish) then reverse PIN 0 back to input so that if the PIR sends another signal it will see it again. Thanks for all the help!
' {$STAMP BS1}
' {$PBASIC 1.0}
'
[noparse][[/noparse] I/O Definitions ]
SYMBOL Trigger = PIN0
SYMBOL Yes = 1
SYMBOL No = 0
'
[noparse][[/noparse] Initialization ]
DIRS = %00001110
'
[noparse][[/noparse] Program Code ]
Main:
IF Trigger = No THEN GOTO Main
If Trigger = Yes THEN GOTO Motor
Motor:
REVERSE PIN0
HIGH PIN1
LOW PIN2
HIGH PIN3
PAUSE 500
LOW PIN1
LOW PIN2
HIGH PIN3
PAUSE 5000
LOW PIN1
HIGH PIN2
HIGH PIN3
PAUSE 500
LOW PIN1
LOW PIN2
HIGH PIN3
NAP 60000
REVERSE PIN0
GOTO Main
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
' {$STAMP BS1}
' {$PBASIC 1.0}
'
[noparse][[/noparse] I/O Definitions ]
SYMBOL Trigger = PIN0
SYMBOL Yes = 1
SYMBOL No = 0
'
[noparse][[/noparse] Initialization ]
DIRS = %00001110
'
[noparse][[/noparse] Program Code ]
Main:
IF Trigger = No THEN Main
IF Trigger = Yes THEN Motor
Motor:
HIGH PIN1
LOW PIN2
HIGH PIN3
PAUSE 500
LOW PIN1
LOW PIN2
HIGH PIN3
PAUSE 5000
LOW PIN1
HIGH PIN2
HIGH PIN3
PAUSE 500
LOW PIN1
LOW PIN2
HIGH PIN3
NAP 54000
GOTO Main
If I have only have "IF Trigger = No THEN Main", then when it checks PIN0 and there's no signal it will just go back to the top of the code and right back to checking again.
But if it checks PIN0 and there is a signal it would continue down the line of commands.
Is that right? So cleaned up it should look like this:
' {$STAMP BS1}
' {$PBASIC 1.0}
'
[noparse][[/noparse] I/O Definitions ]
SYMBOL Trigger = PIN0
SYMBOL No = 0
'
[noparse][[/noparse] Initialization ]
DIRS = %00001110
'
[noparse][[/noparse] Program Code ]
Main:
IF Trigger = No THEN Main
HIGH PIN1
LOW PIN2
HIGH PIN3
PAUSE 500
LOW PIN1
LOW PIN2
HIGH PIN3
PAUSE 5000
LOW PIN1
HIGH PIN2
HIGH PIN3
PAUSE 500
LOW PIN1
LOW PIN2
HIGH PIN3
NAP 54000
GOTO Main
This would make Pins 1,2, and 3 output, aka HIGH, wouldn't it? So whenever I start the program those pins would start outputting a HIGH signal, which I don't want to do until the program tells those pins to.
So, in actuality, I would really want to set the DIRS to %00000000 wouldn't I?