Push button, run 60sec, turn off

Hey everyone,
So I am trying build a counter that uses a d/c motor and and a lazer with a photo resistor to count the rotations of of a disc that turns. Basically, there is a disc attached to a motor shaft that turns when the motor is turned on. The photo resistor will count how many times the lazer hits it and keep track of the data. I want the motor to run and the counter to start taking in data for 60 seconds after pushing a button, then stop the motor and data intake after 60seconds. I have a code but want to know if the timer is correct on it. Thanks for the help.

Vescometer.ino (1.68 KB)

Please post your code here to make it easier to examine. When you post it please use code tags (</> icon, top/left of the forum editor)

      if(countPin==HIGH){          //starts counter for photoresistor

11 is not equal to HIGH, so this statement will never evaluate to true.

 pinMode(countPin,OUTPUT);

What, exactly, is connected to this pin?

   if (flag=1){

Assigning the value 1 to flag in an if statement rarely makes sense.

   unsigned long timePassed=timePassed+(currentTime-pastTime);

Creating a local variable with the same name as a global variable is rarely a good idea. Using the global variable in the definition of the local variable is DEFINITELY a crappy idea.

Having the local and global variables have different types is definitely a bad idea.

  {
    if(timePassed>=0);
    digitalWrite(motorPin, LOW);
      digitalWrite(countPin,LOW);
      flag=0;//change flag variable again
    
   }

Useless curly braces are not a good idea.

The if statement is pointless. If timePassed is greater than 0, do nothing (;). Otherwise, do nothing. Why bother testing?

The random indenting in your code is not a good idea. Use Tools + Auto Format to fix that.

int -32,768 to 32,767

int timePassed=60000; :wink: