First of all, I'd like to thank you for following up with me and bearing my simple questions!Like I said. A sets a flag. When B is tripped it sees if A flag is set. That means someone came in.
If B is tripped it checks to see if A flag is set. If not then it sets a B flag. When A is tripped, it checks the B flag. If set then that means someone is exiting.
Your problem is going to be if people try to enter and exit at exactly the same time. Then I don't know what to do.
You could get really fancy when A is tripped, it starts a timer. If B is not tripped then the enter count is canceled. It means they changed thier mind.
Thank you for the advice about the infared light but what I'm actually doing is a prototype for a project(a small wooden house) so I do not think that is my current problem.A infrared LED and a photo-diode do not by themselves make a great switch. room lite can have a false trigger.
To count if some one come's in you would need a sensor on the inside of the door to see if they exited you'll need one on the outside. Like you said.
That would make coding easy
Like this sensor_out as variable and sensor_in as variable. and a counter
Your code would be like this this is in basic But it easy to write it in C to
Just a idea I would blink my Infra red diode at 38 to 40 khz that would keep room light from interfering. And test to see if your receiving light from your Infra red diodeRich (BB code):dim sensor_out as byte dim sensor_in as byte dim counter_in as byte dim counter_out as byte If sensor_in = 1 and sensor_out =0 then counter_in = counter_in +1 counter_out = counter_in //you can add action code here elseif sensor_out = 1 and sensor_in = 0 then counter_out = counter_out - 1 endif
It is easy.I know that I have to add up all the people that entered and subtract all those who went out. The problem is how do I get the PIC to differentiate if A occured before B or B occured before A (meaning if the 1st sensor was crossed before the second one=> person in, and if the 2nd sensor was crossed then the 1st one was crossed after=> a person out)?
Thank you again I'm looking forward to your reply.
Yes be80be,Have a little look at this