Shop OBEX P1 Docs P2 Docs Learn Events
BOE and a PIR SENSOR — Parallax Forums

BOE and a PIR SENSOR

JRC610JRC610 Posts: 11
edited 2008-08-10 07:07 in BASIC Stamp
Can somebody help me? I am new to this and can't get this to work right.
I have a BOE and a PIR Sensor that I am trying to get a LED to go on and off with the High and Low signal from the PIR. The LED will go on with the High but not go off with the Low, it just stays on.
This is what I wrote so far, like I said I am new to this.

' This program displays the current state of the PIR Sensor connected to P0
' on the DEBUG screen. Flashes a LED Connected to P1.
'
[noparse][[/noparse] I/O Description ]
PIR = IN0· ' I/O Pin For PIR Sensor
LED = IN1· 'I/O Pin For LED
'
[noparse][[/noparse]Variables ]
PIR VAR Bit
LED VAR Bit
'
[noparse][[/noparse] Program Code ]
·DO
··LED = IN1
· DEBUG HOME, BIN1· IN0 ' Display Status Of P0 At Home Pos.
· PAUSE 100·· ' Same Delay
· IF (PIR = 0) THEN
··· LOW· 0·· ' Zero means 'off'. Set 'Low' to turn off LED
· ELSE
··· HIGH· 1·· ' 1 means "on". Set 'High' to turn ON LED
· ENDIF
· LOOP······· ' Repeat Forever
The other question that I have is the PIR Sensor supposed to go from low to high even if there is nothing in its view? It puts out a High singal about every 3 seconds for about 3 seconds. Yes it will do it the whole time it is on, Even after the warm up time.

Comments

  • FranklinFranklin Posts: 4,747
    edited 2008-08-05 18:12
    Add a 'pull down' resistor (10K) between the pin and ground and try that.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • JRC610JRC610 Posts: 11
    edited 2008-08-05 22:15
    Between which pin and ground? The led has a built in resistor.
  • FranklinFranklin Posts: 4,747
    edited 2008-08-05 22:54
    PIR pin

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • JRC610JRC610 Posts: 11
    edited 2008-08-09 05:22
    I put the 10K in and it still does the samething.
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2008-08-09 13:18
    LED = IN1... LED = IN1...

    Should LED be an Output?
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2008-08-09 15:26
    Hi JRC610, along with the previous advice the following line is not right

    LOW· 0·· ' Zero means 'off'. Set 'Low' to turn off LED

    Your LED is connected to P1, the instructions to turn the LED on and off are as follows

    HIGH··1·· '·HIGH means 'set P1 logic 1'. Set 'HIGH' to turn on LED
    LOW··1·· '·LOW means 'set P1 logic 0'. Set 'Low' to turn off LED

    Jeff T.
  • JRC610JRC610 Posts: 11
    edited 2008-08-09 18:17
    I have changed my code, it works with movement but it still puts off a false trigger when there is no movement. Like I wrote before it blinks on every 2 to 3 seconds and stays on for 4 to 5 seconds. I have a 10k pull down resistor at the PIR sensor and still does it. Beginning to think I have a bad sensor. Can anyone tell me if this is normal for the sensor to do?
  • JRC610JRC610 Posts: 11
    edited 2008-08-09 18:19
    Sorry here is my code

    ' This program displays the current state of the PIR Sensor connected to P15
    ' on the DEBUG screen. Signal from PIR Sensor Flashes a LED Connected to P1.
    '
    [noparse][[/noparse] I/O Description ]
    PIR = IN15· ' I/O Pin For PIR Sensor
    LED = IN1· 'I/O Pin For LED
    '
    [noparse][[/noparse]Variables ]
    PIR VAR Bit
    LED VAR Bit
    '
    [noparse][[/noparse] Program Code ]
    DO
    · DEBUG HOME, BIN1· IN15·· ' Display Status Of P15 At Home Pos.
    · 'PAUSE 100··············· ' Same Delay
    · IF IN15 = 0 THEN
    ··· LOW 1
    · ENDIF
    · IF IN15 = 1 THEN
    ··· HIGH 1
    ··· 'PAUSE 100
    · ENDIF
    LOOP
    'HIGH· 1·· ' HIGH means 'set P1 logic 1'. Set 'HIGH' to turn on LED
    'LOW· 1·· ' LOW means 'set P1 logic 0'. Set 'Low' to turn off LED
  • JRC610JRC610 Posts: 11
    edited 2008-08-09 23:13
    Hello everybody,

    Ok I got fed up with trying to get it to work. I went out and bought another PIR Sensor. This one works, it does not blink on and off. If it does then it is not working properly. Now I have to figure out how to use a timer to keep a LED lit for 10 min. Is this possible?
  • SRLMSRLM Posts: 5,045
    edited 2008-08-10 06:11
    For the code that you posted, you don't need the bits... Just to clean it up. Anyway, yes, it is quite possible an easy to keep the LED on for ten minutes. Might I take a moment to recomend that you read throught the Reference and Syntax manual a couple of times? You can't use the language effectively without understanding it and knowing where to look for things that you don't.

    Anyway, there are two choices for you: the pause command and the sleep command. The pause command is simple:

    LED    PIN   1
    Timer  VAR   WORD
     
     
    HIGH LED
     
    'Number of minutes
    For Timer = 0 to 10
     
    PAUSE 60000
     
    

    However, with the pause command, your BS2 will still consume a relatively high current. The tradeoff is the sleep command. With this command, your units are in seconds, rounded to the nearest multiple of 2.304. However, the sleep command causes a slight flicker every once in a while in the circuit. This is contered by a very low power consumption.
  • JRC610JRC610 Posts: 11
    edited 2008-08-10 07:07
    Thank you I will try it.
Sign In or Register to comment.