I am building a timing system that has a start, split and finish beams with this I am using a start gate that will drop when the race starts. when it drops it will trip the 1st sensor starting to count the millis which I am using to calculate the time. I am using IR sensors to that give me the 3 times based on the millis and then I do a calculation in excel that will give me the split and finish time.
Where I am running into issues is that after the person goes through the 3 timer sensors I have to close the start gate which trips the first sensor which messes up my times for the next person.
So I need to adjust my sketch so it takes this into consideration when it starts counting the millis. Basically I am thinking it needs a line of code to have the 1st sensor == LOW once and do nothing and then on the 2nd time that same sensor is == LOW it records the millis from that point.
Below is the sketch I am working on.
//timer
unsigned long start, reaction, push, elapsed;
void setup()
{
Serial.begin(115200);
pinMode(2, INPUT); // start switch
pinMode(3, INPUT); // split sensor
pinMode(4, INPUT); // finish sensor
}
void loop(){
if (digitalRead(2) == LOW)
{
start = millis();
}
if (digitalRead(3) == HIGH)
{
reaction = millis();
// delay(200); // for debounce
}
if (digitalRead(4)==HIGH)
{
push=millis();
delay(500); // for debounce
Serial.print(start);
Serial.print(",");
Serial.print(reaction);
Serial.print(",");
Serial.print(push);
Serial.println();
}
}
start
to the current time. But then you you actually start the next race, you code overwritesstart
with the correct value. As long as you reset the gate after the last sensor is triggers (which actually prints out the times), you're fine, as far as I can see.s/m
notm/s
. You should divide the distance (which I assume is 1m) by the number of seconds (which is 0.1574 and 0.557). Then you get an average of 0.64m/s in the first section. And an average of 1.8m/s in the second section.