I want to set up a Arduino and two pir motion detectors positioned about twenty feet apart on a small country dirt road to gather data on how much traffic passes and in what direction. I have light dependent resistors to sense when the pir detectors transmit a triggering signal when a car passes by each sensor. My code will work ok detecting the occurrence and the date and time but I haven't figured how to detect the direction of travel. There will be some time pass between the first sensor and the second triggers traveling in both directions. Have looked but not found any sample code to use so far. Probably will be light traffic, 20 to 30 vehicles per day?? Maybe State machine?? Using Arduino r3 and data logging shield. Thanks, Terry
tgathright:
My code will work ok detecting the occurrence and the date and time but I haven't figured how to detect the direction of travel. There will be some time pass between the first sensor and the second triggers traveling in both directions.
Well, if a vehicle triggers A before B, there are two possibilities:
It is travelling from A to B.
It is travellling from B to A, but also travelling backwards in time.
With the equipment you have there will be some limitations, but with long intervals between vehicles they may not matter.
You need to figure out an interval of time which is longer than the longest time for a vehicle to traverse the sensors.
After a long interval when a detector is triggered record the time (millis() ) and note which detector was triggered. Then record the time when the 2nd detector is triggered. As long as the difference between the times is shorter than the long interval you can assume it is a legitimate detection of a vehicle. The direction will obviously be identified by the detector that was triggered first.
It would probably also be a good idea to discard intervals that are too short as they might represent birds or 2 vehicles travelling in opposite directions.
Robin2:
It would probably also be a good idea to discard intervals that are too short as they might represent birds or 2 vehicles travelling in opposite directions.
...R
Or too long. What are the chances of a bird triggering both beams? What about pedestrians?