Shop OBEX P1 Docs P2 Docs Learn Events
Cuont up and down — Parallax Forums

Cuont up and down

Joe SchisslerJoe Schissler Posts: 22
edited 2012-04-14 06:45 in General Discussion
We have one door in and one door out of the store room. I need to count the number of people going in and then out. I've looked at all the books etc. But still see no evidence of this type of counting. If you can't guess i'm a noobe. I have some electronic experience. Would like someone to point me in the right direction. I AM USING A BS2 AND PROX SENSORS
Thank you

Comments

  • ElectricAyeElectricAye Posts: 4,561
    edited 2012-04-11 14:51
    Hi Joe,

    welcome to the forum. What sort of prox sensors are you using?
    Keep in mind that counting the number of times the door opens and closes does not necessarily reflect the number of bodies moving in and out. Does it matter to you if people open the door but don't enter, then let the door close? Will it matter much to you if the door is opened and two or three people move through it at one time? These are the kinds of things you will need to think about.
  • LeonLeon Posts: 7,620
    edited 2012-04-11 14:52
    It's very difficult to do that accurately. I designed the first version of this people counter which would do what you want:

    http://www.irisys.co.uk/people-counting/

    It's rather expensive, though.
  • ElectricAyeElectricAye Posts: 4,561
    edited 2012-04-11 15:38
    Leon, I wonder if a similar system could be kluged from a Kinect sensor?
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2012-04-12 00:13
    You actually might be better with a couple of floor mat senors than proximity sensors. The proximity sensors generally presume that people would have to line up and wait their turn to enter or exit. Unless you actually impose a turnstile, people will always muddle ahead in rather unpredictiable ways. Beside this, determining actual direction is problematic. For instance, what if a person gets to the door's threshold and decides to turn around and not enter?

    Having two sensor systems that confirm their independent counts is likely even better. PIRs track body heat and are another likely way to count people if they are well posistioned.
  • Joe SchisslerJoe Schissler Posts: 22
    edited 2012-04-12 05:29
    We have one door in and one door out of the store room. I need to count the number of people going in and then out. I've looked at all the books etc. But still see no evidence of this type of counting. If you can't guess i'm a noobe. I have some electronic experience. Would like someone to point me in the right direction. I AM USING A BS2 . Actually we have a turnstyle . My problem is the program. I can't get it to work on the benchtop. I've tryed many different configurations and no luck.
    Thank you
  • ElectricAyeElectricAye Posts: 4,561
    edited 2012-04-12 06:36
    ... Actually we have a turnstyle . My problem is the program. I can't get it to work on the benchtop....

    Hi Joe,

    Do you have any idea how the switch system inside the turnstile is set up?

    You should post your code so we know what you're doing. See the link below for how to use CODE tags.


    attachment.php?attachmentid=78421&d=1297987572
  • Joe SchisslerJoe Schissler Posts: 22
    edited 2012-04-12 08:16
    the sensors are microswitches on a cam system one on the in door and one on the out door.
  • ElectricAyeElectricAye Posts: 4,561
    edited 2012-04-12 09:37
    the sensors are microswitches on a cam system one on the in door and one on the out door.

    Okay, so if you look on page 133 of the Basic Stamp manual (version 2.1), you'll find a command called Button. Have a look at that and you should be able to figure out how to wire up the microswitches using this sort of schematic.

    If that does not work, then it's probably your software, which you will need to post.

    I'm guessing your turnstiles are not powered in any way, correct? You want your switches to operate on only the power you provide to them via your BS2 circuitry.

    PushButton1.gif
    640 x 248 - 13K
  • skylightskylight Posts: 1,915
    edited 2012-04-12 09:38
    Have two sensors on each door one before and one after and have logic that ignores the second sensor if the first hasn't been triggered and only counts up or down if both sensors on a door have been triggered.in the correct order,otherwise it sets an alarm flag to state that someone has tried to trick the system.
  • Joe SchisslerJoe Schissler Posts: 22
    edited 2012-04-12 10:43
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}

    counter VAR Byte 'declares "counter"
    DEBUG "Programme Running..."
    DEBUG "COUNTER"
    PIN 8 INPUT
    PIN 9 INPUT
    FOR counter = 1 TO 150
    PIN 8 COUNTS UP 'counts up when switch is closed. "in"
    PIN 9 COUNTS DOWN 'counts down when switch is closed. "out"
    NEXT
  • ElectricAyeElectricAye Posts: 4,561
    edited 2012-04-12 11:22
    Joe,

    have a look at Chapter 3 of this free download, What's a Microcontroller?

    www.parallax.com/Portals/0/Downloads/.../28123-WAM-v3.0.pdf

    It will teach you how to wire up the switches and get variables to record your counts, etc. I'm no expert on the Basic Stamp, but right now I can't understand how your code is supposed to work.
    What you want to do with the turnstile is fairly simple, so don't get discouraged. You just need to read Chapter 3, I think.

    I hope that helps.
  • Joe SchisslerJoe Schissler Posts: 22
    edited 2012-04-12 13:32
    ok got that. Now how do I add in the counter

    ' What's a Microcontroller - PushbuttonControlOfTwoLeds.bs2
    ' Blink P14 LED if P3 pushbutton is pressed, and blink P15 LED if
    ' P4 pushbutton is pressed.
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}

    PAUSE 1000
    DO
    DEBUG HOME
    DEBUG ? IN4
    DEBUG ? IN3
    IF (IN3 = 1) AND (IN4 = 1) THEN
    HIGH 14
    HIGH 15
    PAUSE 50
    ELSEIF (IN3 = 1) THEN
    HIGH 14
    PAUSE 50
    ELSEIF (IN4 = 1) THEN
    HIGH 15
    PAUSE 50
    ELSE
    PAUSE 50
    ENDIF
    LOW 14
    LOW 15
    PAUSE 50
    LOOP
  • ElectricAyeElectricAye Posts: 4,561
    edited 2012-04-12 14:24
    I'm away from my junk, so I can't test this. But I think something like this ought to work
    Note that the program will wait about 1 second after a switch is tripped so it won't credit thousands of people entering just because the microswitch is in a high state on each loop.
    In other words, people have one second to get through the turnstile, otherwise it will rack up more counts than it should.
    But do you need to consider what will happen if somebody is entering at the same time somebody else is exiting? That would be a problem with this code.
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
    Counter VAR Word
    
    DO 'Begin the Do Loop...
    
      DEBUG HOME
      DEBUG Dec Counter
      IF (IN3 = 1)  THEN 'People are going into the warehouse.
        Counter = Counter + 1
        PAUSE 1000  'Debounce the switch
      ENDIF
    
      IF (IN4 = 1)  THEN 'People are exiting the warehouse.
        Counter = Counter - 1
        PAUSE 1000  'Debounce the switch
      ENDIF
    
    LOOP
    
    END
    
    
  • Joe SchisslerJoe Schissler Posts: 22
    edited 2012-04-13 06:38
    THANK YOU SOOO MUCH . i WAS GOING NUTS ABOUT THIS. MY WIFE THOUGHT I WAS NUTS . I PLUGED THE PROGRAM IN AND RAN IT .I SEE THE ONLY PROBLEM IS IF BOTH SWITCHES ARE CLOSED AT THE SAME TIME.
    THANKS AGAIN
    JOE
  • ElectricAyeElectricAye Posts: 4,561
    edited 2012-04-13 08:28
    ....I SEE THE ONLY PROBLEM IS IF BOTH SWITCHES ARE CLOSED AT THE SAME TIME.
    ...

    Hi Joe,

    Yes, that's a problem. I confess it's been a long time since I've done much with the Basic Stamp (I normally work with the Propeller chip), so perhaps somebody can suggest an easy way to work around that problem. I know there is a BUTTON command, but I don't know if it can overcome this problem. Another thing you might need to play with is the pause time given for "debouncing" your turnstile switch. Pause 1000 gives you 1 second to get through the turnstile, but you might find that's not enough time. So you might want to make it Pause 2000 for 2 seconds, or something else to make it work right.

    I'm glad you're making progress with it.
  • jmgjmg Posts: 15,184
    edited 2012-04-13 13:15
    You might prefer to edge-activate the counter, and a saturating counter also avoids embarrassing numbers...
    (not tested)
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
    Counter VAR Word
    Last_IN3 VAR bit
    Last_IN4 VAR bit
    DebDly CON 20      ' reduce this until it double counts, then x5 
    
    
    Last_IN3 = IN3
    Last_IN4 = IN4
    
    DO 'Begin the Do Loop...
    
      DEBUG HOME
      DEBUG Dec Counter
      IF (IN3 = 1) AND (Last_IN3=0)  THEN   '  SW _/=   People are going into the warehouse.
        Counter = Counter + 1
        PAUSE  DebDly     ' Debounce the switch - can now be much shorter
      ENDIF
      Last_IN3 = IN3
    
      IF (IN4 &/ Last_IN4)   THEN '  SW _/=  People are exiting the warehouse.
        IF Counter > 0 THEN 
           Counter = Counter - 1   ' Saturating counter, spin the exit to clear to zero..correct any creepage.
        ENDIF
        PAUSE  DebDly  ' Debounce the switch
      ENDIF
      Last_IN4 = IN4
    
    LOOP
    
    END
    
    

    I see there is an AND NOT operator (&/), so I added that example for IN4, and the statements
    (IN3 = 1) AND (Last_IN3=0)
    and
    (IN4 &/ Last_IN4)
    could be tested to see which is smaller/faster (Or you can nest two IF statements & test that too )
  • Joe SchisslerJoe Schissler Posts: 22
    edited 2012-04-13 17:34
    Thanks!! I'll give it a try and play with it .
    Joe
  • Joe SchisslerJoe Schissler Posts: 22
    edited 2012-04-13 18:54
    It counts up and down. But counting down from 10 it shows 90,80,70,60,50,40,30,20,10,00. Why is it keeping the extra 0? EVEN WHEN IT REACHES 0, OR IF YOU RESET IT?
  • jmgjmg Posts: 15,184
    edited 2012-04-13 19:09
    It counts up and down. But counting down from 10 it shows 90,80,70,60,50,40,30,20,10,00. Why is it keeping the extra 0? EVEN WHEN IT REACHES 0, OR IF YOU RESET IT?

    Does it do the same on Count UP ? ( and does it stop at 0, as expected ?)
    What happens as you vary the constant DebDly ?
  • ElectricAyeElectricAye Posts: 4,561
    edited 2012-04-13 19:29
    Is it possible that you need a DEBUG CLS command to clear all the old numbers so the new numbers don't overwrite the old and leave on the 0 from the previous display?

    .
    .
    .
    DEBUG HOME
    DEBUG CLS
    DEBUG DEC COUNTER
    .
    .
    .
  • Joe SchisslerJoe Schissler Posts: 22
    edited 2012-04-14 03:44
    How do I do the math ??
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    'Two counters one for people entering and one for leaving.
    'The difference "C" is the number of people in the store
    CounterA VAR Byte 'People entering store
    CounterB VAR Byte 'People leaving store
    C VAR Byte 'People in store
    DO

    DEBUG HOME

    DEBUG DEC CounterA, CR
    DEBUG DEC COUNTERB, CR
    DEBUG DEC C 'People in store
    IF (IN3 = 1) THEN
    CounterA = CounterA + 1 'People entering store
    PAUSE 200
    ENDIF
    IF (IN4 = 1) THEN
    CounterB = CounterB + 1 'People leaving store
    PAUSE 200
    ENDIF

    LOOP

    END
  • ElectricAyeElectricAye Posts: 4,561
    edited 2012-04-14 06:00
    How do I do the math ??...

    CounterC = CounterA - CounterB

    DEBUG DEC CounterC 'People in store


    Joe,

    just so you know, there's a forum here dedicated to just the Basic Stamp. Right now you are in the General Discussion forum.
    If you're working with the Basic Stamp, then feel free to post questions at the Basic Stamp forum, too: http://forums.parallax.com/forumdisplay.php?48-BASIC-Stamp

    Did you ever solve your problem with your unit apparently counting by 10's .. 10, 20, 30...? Or did the "clear screen" command, DEBUG CLS, solve your problem?
  • Joe SchisslerJoe Schissler Posts: 22
    edited 2012-04-14 06:45
    cls solved the problem
    thanks a million
    Joe
Sign In or Register to comment.