Basic Stamp 2,LEDS,PIR motion sensor,newbie
AFWS
Posts: 3
OK,a complete newbie to this stuff.I'm trying to get 6 leds to go off once it's triggered by the PIR motion sensor.I've got the leds doing what I'm wanting. I just can't get the motion sensor to control em,any ideas? Found all kinds of stuff online on how to hook up leds and the PIR motion sensor.Just not how to get it to control em.
Comments
"What's a Microcontroller?" is the introductory text for the Basic Stamps. It covers controlling LEDs and being controlled by pushbuttons and switches. Some PIR sensors act like switches. Basically, you have a program that initializes things, then waits for some signal from the PIR sensor. Once the Stamp detects the PIR trigger signal, the program stops going round and round in a loop waiting for the PIR sensor and it continues on to a portion of the program that controls the LEDs and presumably makes them indicate that the PIR sensor has triggered. After that, the program has to go back to wait on the PIR sensor again. If the PIR sensor acts like a switch, the program has to make sure that the PIR sensor has reset itself before the program waits for another trigger. This is true for switches and pushbuttons as well.
Here's how I've got the leds hooked up but in different pins.
I don't know if it's how I've got things hooked up or I'm not tell it to do the right thing? It's seems to by pass the motion sensor and loop the lights.I've tried looping, ending ,everything under the sun.
' {$STAMP BS2}
' {$PBASIC 2.5}
DEBUG "Warming up..."
PAUSE 20000 ' PIR warm-up time
DEBUG CLS
DO
HIGH 0 ' Display state of PIR sensor
PAUSE 100 ' Small Delay
HIGH 2 ' Headlights On
HIGH 1
PAUSE 10000
N VAR Byte
FOR N = 1 TO 8
HIGH 4 ' Left Blinker Tail Light On
HIGH 6
PAUSE 300
LOW 4 ' Left Blinker Tail Light Off
LOW 6
PAUSE 400
NEXT
PAUSE 2000
X VAR Byte
FOR X = 1 TO 8
HIGH 8 ' Right Blinker Tail Light On
HIGH 10
PAUSE 300
LOW 8 ' Right Blinker Tail Light Off
LOW 10
PAUSE 400
NEXT
PAUSE 2000
Y VAR Byte
FOR Y = 1 TO 8
HIGH 4 ' Left Blinker Tail Light On
HIGH 6
PAUSE 300
LOW 4 ' Left Blinker Tail Light Off
LOW 6
PAUSE 400
NEXT
PAUSE 2000
Z VAR Byte
FOR Z = 1 TO 8
HIGH 8 ' Right Blinker Tail Light On
HIGH 10
PAUSE 300
LOW 8 ' Right Blinker Tail Light Off
LOW 10
PAUSE 400
NEXT
PAUSE 5000
LOW 2 ' Headlights Off
LOW 1
PAUSE 10000
LOOP
You have a comment "Display state of PIR sensor" on a line of your program that has a HIGH 0, but that's not what the line does. HIGH 0 sets I/O pin 0 to output mode and the signal on pin 0 is set to high (+5V). You should put something there that tests the state of pin 0 like "DEBUG IN0". If you want the program to blink the LEDs when the PIR sensor triggers, you need to have something like "wait: IF IN0 = 0 THEN GOTO wait" there.
x var byte
x = 0
repeat: x=x +1
debug dec x, cr
if x <= 30 then repeat
debug "all done"
I tried this and it doesn't seem to do anything.I tried putting it at the beginning and the end of the program.
The "x = 0" is the initialization for the loop. The "repeat: x = x + 1" is the start of the loop. The "debug dec x, cr" is the action part of the loop ... the thing that gets repeated. The "if x <= 30 then goto repeat" is the tail or end of the loop where the looping occurs. The final debug comes after the loop is all done.
In your case, the stuff before the "DO" is the initialization section. The start of the loop is after you test for the PIR sensor triggering. Everything from that point to the last "PAUSE 10000" is the action part of the loop. The tail of the new loop comes just before the "LOOP" statement.
Do read and work through the examples in "What's a Microcontroller?". You'll learn all this stuff.