+ Reply to Thread
Results 1 to 6 of 6

Thread: Basic Stamp 2,LEDS,PIR motion sensor,newbie

  1. #1

    Default Basic Stamp 2,LEDS,PIR motion sensor,newbie

    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.

  2. #2

    Default Re: Basic Stamp 2,LEDS,PIR motion sensor,newbie

    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.

  3. #3

    Default Re: Basic Stamp 2,LEDS,PIR motion sensor,newbie

    I'm using Parallax's.Here's how I've basically got the sensor hooked up

    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

  4. #4

    Default Re: Basic Stamp 2,LEDS,PIR motion sensor,newbie

    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.

  5. #5

    Default Re: Basic Stamp 2,LEDS,PIR motion sensor,newbie

    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.

  6. #6

    Default Re: Basic Stamp 2,LEDS,PIR motion sensor,newbie

    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.

+ Reply to Thread

Similar Threads

  1. [unsolved] Creating a Program with BASIC Stamp (2.5.3) and LEDs
    By jellybean1865 in forum BASIC Stamp
    Replies: 19
    Last Post: 10-11-2012, 05:46 AM
  2. basic stamp: music with flashing leds.
    By gmchuslo in forum BASIC Stamp
    Replies: 2
    Last Post: 11-24-2011, 05:00 PM
  3. Using BASIC Stamp To Control A Board with 215 LEDs
    By Hobbes24 in forum BASIC Stamp
    Replies: 11
    Last Post: 12-02-2009, 12:41 AM
  4. Sound reactant leds with basic stamp board
    By ryester1120 in forum BASIC Stamp
    Replies: 1
    Last Post: 02-12-2008, 12:20 AM
  5. sculpture project basic stamp and leds
    By Archiver in forum BASIC Stamps Archive
    Replies: 21
    Last Post: 03-29-2004, 02:44 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts