Share knowledge with Arduino code writing.
Recording traffic count,time,date and direction on a small public dirt road bordering my property at Ms. and storing the data to a sd card and/or thermal printer. The road is narrow, two vehicles can pass by each other traveling in opposite directions but it would be considered as a one lane road. Lightly used, probably less than one vehicle per hour???
Two HC- SR501 PIR motion sensors hooded inside black 1-1/2" pipes to reduce sensitivity and placed about 20 feet apart along the North and South roadway. Arduino r3 with datalogging shield is supplying power and receiving signals over a distance of 300 feet using telephone wire. I plan to put a 100uf and a 0.1uf ceramic cap at both ends of the power supply but do not have them installed on the mock up at home now.
Have a mock setup using the 300 feet of cable at my home in Metairie, La. and aiming the hooded motion sensors at traffic passing my street. Seems to work fairly well but could be much better if the code would be refined and added to. It records the time, date and sensor readings for each one and I can look and see which one comes in first and determine which direction the vehicle was traveling.
When a sensor fires it stays high for about three seconds and would print a whole page to the sd card and sometimes miss the second sensor because it is still busy with the first. I put in a one second delay but it still prints about three lines to the sd card and will sometimes miss the second sensor. Have had no luck setting the and <triggering , retriggering>settings on the motion sensors. Seems like it would be possible to have the arduino to refuse to log any more signals from that source after receiving one for a variable< millis> time then record the signal from the other and not receive any for another then record the direction of travel, time,date and increment a counter. Have studied the example code and Nick Gammond’s " How to do multiple things at once" but it is hard for me.
Here is my code for now, probably needs improvement. Love these little microprocessors, amazed at what is possible. I am a 72 year old retired pipefitter so my experience with this is limited. What would be fair if I paid for someone to write the code for me?

Alarm_To_SD_Card_6_15_16.ino (9.43 KB)

First, while the code is in your Arduino IDE, press Ctrl-T to format it into a standard C style. It makes it easier for us to read.

Second, if you remove the duplicate code at the bottom, it should be less than 9K in size, which will allow you to post it here. Readers of this Forum prefer to have the code listed as nasty people can embed some bad stuff in files. Make sure you use code tags (</>) for posting your code. If this is unclear, read Nick’s post at the top of this Forum for posting code here.

Third, can you give a little more details on the function of the North and South indicators (pins 8 and 9) and the sensor pins (pins 3 and 4). I think I understand their purpose, but perhaps additional details would help.

cool project - don’t pay someone, you’ve gone a long way already

On your HC-SR501 PIR motion sensors indeed the Trimpot Tx will set the Trigger length between 5sec - 200sec… so your pin will stay high at least 5 sec (may be 3 if it’s a cheap Trimpot :-))

So yes you will need to deal with this.

for that you will need two variables for storing the last Trigger time for each sensor

 unsigned long lastNorthTrigger =0, lastSouthTrigger=0;

and you need a minimum delay you want to wait before accepting again a trigger from a sensor

#define TRIGGERDELAY 3000L

if your code, instead of doing

 if (North_sensorValue > 0) //<100) {

you really want to execute the logging if this is not the same alarm as before, so you will do

if  ((North_sensorValue == HIGH) && (millis() - lastNorthTrigger > TRIGGERDELAY)) {
       lastNorthTrigger = millis() ;

(I replaced
* *> 0* *
* *== HIGH* *
because you are doing an digitalRead, so value is either LOW or HIGH)

this way you can only record information if 3 seconds (3000 milliseconds in TRIGGERDELAY) have passed

you apply the same logic for South

and get rid of the delays in your code - you don’t want to wait for no specific reason