Shop OBEX P1 Docs P2 Docs Learn Events
Basic Stamp 2,LEDS,PIR motion sensor,newbie — Parallax Forums

Basic Stamp 2,LEDS,PIR motion sensor,newbie

AFWSAFWS Posts: 3
edited 2012-10-28 11:49 in BASIC Stamp
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

  • Mike GreenMike Green Posts: 23,101
    edited 2012-10-27 17:19
    What PIR sensor are you using? Include a link to its documentation if it's not Parallax's.

    "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.
  • AFWSAFWS Posts: 3
    edited 2012-10-28 05:48
    I'm using Parallax's.Here's how I've basically got the sensor hooked up PIR-4.png

    Here's how I've got the leds hooked up but in different pins.
    309895.image0.jpg
    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
  • Mike GreenMike Green Posts: 23,101
    edited 2012-10-28 07:17
    I don't see any place where you test the state of the PIR sensor. You let it warm up, then you start a loop where you fiddle with the LEDs.

    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.
  • AFWSAFWS Posts: 3
    edited 2012-10-28 10:49
    WOW! this stuff is a workout,LOL I finally got it to work with your help.Is there a way I can loop the program a certain number times then turn off? I found this in some reading "You can have a program branch depending on the value of a variable.For example,this program will run the loop 30 times then branch"

    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.
  • Mike GreenMike Green Posts: 23,101
    edited 2012-10-28 11:49
    As is true of most examples, you can't just copy it into some arbitrary place in your program. It's an example of how to do something. You have to take a moment (or two) to understand how it works first, then figure out how to apply the example to what you want to do.

    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.
Sign In or Register to comment.