May 18, 2024, 06:43:16 PM

News:

Got VSA?  Want to use your Prop-SX?  Now you can!  See the VSA section of the Library forum for Prop-SX code that works with VSA.


Multiple PIR on same Prop-1 PIN ?

Started by BigRez, November 07, 2008, 04:42:55 PM

Previous topic - Next topic

BigRez

Getting a jump-start on Halloween 2009...

I'd like to create an automatic "door" that will open to traffic in either direction.  To do this, I'll place a PIR on either side of the door.  PIR activity opens the door.  Once open, it's stay open for at least 5 seconds after the last PIR activity.

Can both PIRs be connected to the same PIN?

Then the programming (pseudo code) would look something like the following.  Is there a better way to do the delay? (In other words, is there a way on a prop-1 to determine how long it's been between two events?)

Close_Door:
   - door isClosed;
   - AC isOff;

Wait_for_PIR:
   - wait for PIR activity;

Open_door:
   - door isOpened;
   - AC isOn;
   - doorTimer = 5000;

Door_Delay:
   - if PIR activity, goto Open_Door
   - pause 100;
   - doorTimer = doorTimer - 100
   - if doorTimer <= 0,  goto Close_Door
   - goto Door_Delay   

JonnyMac

I would not try it.  The reason is that the PIR signal pin is an output and when one is high and the other low you will have a short circuit and then... poof!... blue smoke.  You might get away with putting a small signal diodes between the outputs and the input pin, but this means a custom wiring connection.  If you've got an extra IO you may as well just use it -- I've got code that independently debounces multiple inputs.

I can write a program for you but you need to specify PIR1 and PIR2; I don't want to guess.
Jon McPhalen
EFX-TEK Hollywood Office

BigRez

If I need pin6 and pin7 on the prop-1 for the PIRs, then I cannot connect an AP-8 (or other serial device), correct?  It's looking more and more like a prop-2 application...  or I'll have to figure some other way to trigger sound into the event using one of the OUTs or PIN0-5.

So, if I go with PIR1 (pin6) and PIR2 (pin7), then the pseudo code above is still accurate, except that PIR really means PIR1 and PIR2.  If the following Check_PIRs is correct, I'm not sure how to both check for PIR activity and delay any activity in Door_Delay.

Check_PIRs:
   PAUSE 5                                                     ' loop pad
   timer = timer + 5 * (PIR1 | PIR2)                ' WILL THIS WORK???
   IF timer < 100 THEN Check_PIRs                ' wait for 0.1 sec input
                                                                      ' valid PIR activity detected
Open_Door:
   ' stuff goes on here to open door and other stuff...
   doorTimer = 5000;                                     ' 5 second delay value


Door_Delay:
   if PIR activity THEN Open_Door          'Not sure what this would look like

   pause 100
   doorTimer = doorTimer - 100
   if doorTimer > 0 THEN Door_Delay

Close_Door:
   ' Should I check one more time for PIR activity before closing?
   'blah blah blah
   goto Reset

JonnyMac

November 07, 2008, 07:09:50 PM #3 Last Edit: November 07, 2008, 07:13:51 PM by JonnyMac
QuoteIf I need pin6 and pin7 on the prop-1 for the PIRs, then I cannot connect an AP-8 (or other serial device), correct?

This is not correct.  The PIR is an active-high device and the ULN acts as a pull-down so you can use ANY pin for the PIR.  I actually wrote program for another forum member that monitor six or seven PIRs and sent commands to an AP-8 and DC-16.

You could create a bit variable that holds the (OR'd) result of the two PIR inputs, the update the debounce code like this:

Main:
  timer = 0                                     ' reset timer

Check_Triggers:
  PAUSE 5                                       ' loop pad
  sensors = PIR1 | PIR2                         ' either active?
  timer = timer + 5 * sensors                   ' update timer
  IF timer < 100 THEN Check_Triggers            ' wait for 0.1 sec input


It will actually be easier for me to write a full program for you if you describe it versus trying to write it in pseudo-code.
Jon McPhalen
EFX-TEK Hollywood Office

BigRez

Thanks Jon!  I'll search for the other post you refer to and follow up with questions if needed.

I see the subtle difference between our two versions of the debounce code; BS1 does not allow parens within expressions. (Otherwise mine would have worked on a BS2.) I also now know that math is performed left to right without any operator precedence.  Got it!  (That'll bite me more than once, I'm sure.)

This gives me plenty of info to play with once I get the prop-1 out of my "old" prop.

Thanks again!