BI-DIRECTIONAL PEOPLE SENSOR AND COUNTER USING ARDUINO BOARD

I am building a bi-directional people sensor and counter using an ARDUINO board.
am very new to this and programming as well.

any suggestons for schematics and the code.

thanks

How reliable does this have to be? What's the application?

It's notoriously difficult to get reliable people counting unless you install turnstiles or some such.


Rob

It's notoriously difficult to get reliable people counting unless you install turnstiles or some such.

That's just not true!

Hire a non-blind guy watching people, and for every person going by bi-directionally, the guy pushes a button on an arduino board.

Dada! Cannot be any simpler or more reliable than that, assuming of course the guy doesn't get drunk.

:slight_smile:

Or just get bored.


Rob

THIS SYSTEM DOESN'T HAVE TO BE VERY RELIABLE BUT AM WONDERING IF ANYONE OUT THERE CAN HELP WITH THE CODE TO RUN A PIC16F8777A OR AN ARDUINO WITH TWO IR SENSORS S1 AND S2 TO PERFORM BIDIRECTIONAL COUNTING IN AND OUT. IN THE FIRST SEQUENCE BREAKING FIRST S1 AND THEN S2 WILL TELL THE MICROCONTROLLER TO INCREMENT THE COUNTER WHILE BREAKING THE SECOND SEQUENCE, FIRST S2 AND THEN S1 WOULD TELL THE MICROCONTROLLER TO DECREMENT THE COUNTER.THE MICROONTROLLER SHOULD ALSO STORE AND TIMESTAMP THE COUNTS AND BE ABLE TO PASS THE TIMESTAMPED DATA TO A REMOTE COMPUTER VIA BLUETOOTH OR WIFI.
ANY HELP WILL BE GREATLY APPRECIATED.

There really is no need to shout.
Have you looked for such code in the forum?
It seems to be a very popular project at the moment - which particular seat of learning is promoting it?

I have looked in the forum but nothing is forthcoming. The closest have got is the 2 rotary encoder code which I think is applicable to my counter.
In checking the external interrupts occuring sequence.
Any suggestions are welcome.

If the area being measured is fairly narrow, you can just setup a couple of what
used to be called "photoelectric eyes" [IIRC], ie the person going by simply breaks
a lightbeam. You don't need interrupts for this, just a simple polled I/O loop.

You might get by with something as simple as a couple of pulsed Leds, a mirror for
reflection, and CdS cells [photoresistors] for pickup.

Well for starters to count you could do this.

my_ISR () {

   // we got here because S1 was activated (and debounced in hardware)
   count += digitalRead(S2) == HIGH ? 1 : -1;

}

An interrupt is not really required here but IMO makes life easier as long as the input signal is clean.


Rob

Thanks for the info. I am using pair of infrared sensors on one side facing the transmitter on the other side, and all I want is the same pair of sensors to command a counter to increment by 1 if a person breaks them in one way (IN) or if the other way round that will mean exit and hence decrement the counter.I was thinking of coding the arduino board to check the sequence in which the sensors were tripped and then decide whether to increment or decrement count.

steffano.

So what happens when some one trips one sensor but then changes her mind an goes back and never trips the second one. Now providing the next person comes in from the opposite it will count backwards and continue to count backwards until some one makes a compleat transit from the original direction.

I was thinking of coding the arduino board to check the sequence in which the sensors were tripped and then decide whether to increment or decrement count.

Which is exactly what my code does. Here's a more verbose version that's possibly clearer to a C beginner

my_ISR () {

   // we got here because S1 was activated (and debounced in hardware)
   if (digitalRead(S2) == HIGH)
       count++;
   else
       count--;   // should test for < 0 as well

}

But as I alluded to in post #1 and Mike just explained more completely there are many pitfalls to this approach.


Rob

The more I read it, the more I admire my non-blind guy idea.

:slight_smile:

Hi Rob,

I am making some good progress with my ISR and to start with am printing the count on the serial monitor.
Have also got a 3 digit common cathode display wired to arduino Mega 2560 and the code to count upto 0-999-0
therefore am wondering how do I call the counting code after the interrupts have occured so as to display the count/counter
(incrementing or decrementing) on the 3 digit seven segment display??

Much appreciated.
Steffano.

how do I call the counting code after the interrupts have occured so as to display the count/counter

That depends entirely on how you have the displays wired up.

Got a circuit diagram?

And how about posting your current code?


Rob

stefanoGizz:
how do I call the counting code after the interrupts have occured so as to display the count/counter
(incrementing or decrementing) on the 3 digit seven segment display??

You have a variable that contains the value you last sent to the display. At the start of the loop you compare this variable with the count variable. If they are not the same you update the display.

Could you give me a starter please? am starting my display with 000, increment and decrement accordingly as the sensors makes and breaks
I need to understand this more please.

It's a really bad idea to put serial I/O in interrupt routines.
It's a good idea to post code inside code tags.

I'm gonna repeat one thing I said previously, and then go away. I see no reason to
mess with interrupts here. It's much easier to use polled I/O instead, and by far,
the best way to learn programming is to learn the easy stuff first. You don't have
100 people a second going past the counter.

What's wrong with using interrupts?can you elaborate pls.

thanks