Cuont up and down
Joe Schissler
Posts: 22
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
Thank you
Comments
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.
http://www.irisys.co.uk/people-counting/
It's rather expensive, though.
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.
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.
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.
' {$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
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.
' 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
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.
THANKS AGAIN
JOE
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.
(not tested)
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
Does it do the same on Count UP ? ( and does it stop at 0, as expected ?)
What happens as you vary the constant DebDly ?
.
.
.
DEBUG HOME
DEBUG CLS
DEBUG DEC COUNTER
.
.
.
' {$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
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?
thanks a million
Joe