Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Bidirectional Door Sensor

Status
Not open for further replies.

zr125

Newbie level 6
Joined
Feb 16, 2011
Messages
13
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,369
Can you give me some idea how to write this in c code?

Im trying to do visitor counter, the sensor is at the door.

there are 2 sensor, which is to differentiate which direction a person is going.

im using IR sensors, lets say a(far from door) and b (near to door), side by side.

if a trigger first, then b, i need to send data to serial port, indicating a person has come in.

if b trigger first, then a, i need to send data to serial port, indicating a person going out.
 

Take a look at the logic that is used to detect shaft rotation direction
 

can you give me link / source? more detail please. :)
 

What Klystron is saying is there is a similarity between what you are doing and the way a rotation detector works. In a shaft rotation detector, there are two sensors which are arranged so a light beam falls on one or the other or both. As in your example, call them sensor A and sensor B. When the shaft rotates in one direction, sensor A, then both then only sensor B will operate, going the other way it will be sensor B then both then only sensor A. As a logic table it looks like this:

Clockwise:
A B
0 0
1 0 <-- note the B=0 when A changes to 1.
1 1
0 1
0 0

Anti-clockwise
A B
0 0
0 1
1 1 <-- note that B=1 when A changes to 1
1 0
0 0

You can see that the direction can be found by looking for the rising edge of one of the signals. As the edge rises, look at the other signal, in one direction it will be low and in the other it will be high, this tells you the direction of rotation.

For checking which way people pass through a doorway, use the same principle. Mount the two sensors close enough together that anyone passing must at some position break both the IR beams. At the instant one beam is broken, read the other one. If passing one way the second beam will not yet have been broken, the other way it will already be broken.

Brian.
 

thanx brian ! anyway, is there any other way to write the code? i mean, not by using this logic.
 

Not really. You can do it electrically with flip-flops but you would still have to read them in software anyway.

The code should be very simple, something like:

if((OldStateOfInputA == 0) && (InputA == 1)) // Detect change of Input A from zero to one.
{
Direction = InputB; // Direction will indicate which beam was broken first
}

OldStateOfInputA = InputA; // Update OldStateOfInputA with it's current state.


You would have to run this code in a loop so it could periodically check the sensor.

Brian.
 
thanks! i will try this.. :)
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top