Shop OBEX P1 Docs P2 Docs Learn Events
PIR lighting control — Parallax Forums

PIR lighting control

bullfrogbullfrog Posts: 2
edited 2014-11-23 06:14 in BASIC Stamp
Hello, I am trying to control the lights in the downstairs of my house using a PIR sensor. actually the goal is to control the lights in each room using a PIR for each room. I am able to set up program a BS2 to control the lights in the first room by programming a counter and inc/dec the counter so that the lights stays on for a short time after no motion in the room. I am at a total loss as to how to do this for multiple rooms........................any direction is much appreaciated.
thanks

Comments

  • SapphireSapphire Posts: 496
    edited 2014-11-22 22:45
    You'll need a separate counter for each PIR (room) that you want to control. Then go through a loop and check each PIR input and adjust its counter accordingly. When you get done with all the PIRs, start over at the top. If you're using PAUSE in your routine, you'll only need one for all the counters, and it triggers the slower on timer to decrement. Here's one way that checks each PIR once per second and decrements the timers once per minute. You could use an array to simplify the counters and IF statements. This is just an example, some refinements may be needed for your specific application.
    ON_TIME CON 10        ' 10 MINUTES 
    
    TIMER VAR BYTE        ' SECONDS TIMER
    CNTR1 VAR BYTE        ' PIR1 TIMER
    CNTR2 VAR BYTE        ' PIR2 TIMER
    
    DO
    
      IF PIR1 = 1 THEN
        OUTP1 = 1
        CNTR1 = ON_TIME
      ENDIF
    
      IF PIR2 = 1 THEN
        OUTP2 = 1
        CNTR2 = ON_TIME
      ENDIF
    
      PAUSE 1000
    
      TIMER = TIMER + 1
    
      IF TIMER = 60 THEN   ' ONE MINUTE ELAPSED
    
        IF CNTR1 > 0 THEN
          CNTR1 = CNTR1 - 1
        ELSE
          OUTP1 = 0
        ENDIF
    
        IF CNTR2 > 0 THEN
          CNTR2 = CNTR2 - 1
        ELSE
          OUTP2 = 0
        ENDIF
    
        TIMER = 0
    
      ENDIF
    
    LOOP
      
    
  • bullfrogbullfrog Posts: 2
    edited 2014-11-23 06:14
    Sapphire, thanks so much for the help. I will try that. just couldn't figure out how to move forward.
    Thanks again
    Steven
Sign In or Register to comment.