how do i make motors run for a set amount of time

I am having an issue with the void loop. I want to run the motors for 25 minutes, and then break out from the loop. How would I do that? This is the code i have so far.

const unsigned X_AXIS_PIN = 2;
const unsigned Y_AXIS_PIN = 1;
const unsigned Z_AXIS_PIN = 0;
const int motor1 = 3;
const int motor2 = 5;
const int motor3 = 10;

void setup()
{
Serial.begin(9600);
pinMode(motor1, OUTPUT);
pinMode(motor2, OUTPUT);
pinMode(motor3, OUTPUT);

}

int x,
y,
z;

void loop()
{
Serial.print(analogRead(X_AXIS_PIN));
Serial.print(" ");
x = analogRead(X_AXIS_PIN);
Serial.print(analogRead(Y_AXIS_PIN));
Serial.print(" ");
y = analogRead(Y_AXIS_PIN);
Serial.println(analogRead(Z_AXIS_PIN));
z = analogRead(Z_AXIS_PIN);
delay(1000);

if( x < 700 && y < 700 && z < 700)
{
for(int i = 0; i < 25000; i++)
{
digitalWrite(motor1, HIGH);
digitalWrite(motor2, HIGH);
digitalWrite(motor3, HIGH);
break;
}

}
return;
}

Have you looked at blink without delay?
You should.

Please, please, please, use code tags.

it s not much help I want to run the motors for 25 minutes then turn them off and keep them off and also break out of the loop

koningice:
it s not much help

Yes and you have got an answer.
Is it help you want or some one to write code for you?

if i wanted someone to write code for me i wouldn t need to come here. I am asking for help if that helped i wouldn't be returning to this post to ask for help.

So explain to us why that answer did not help?
Have you done anything about looking at that example?
Did you understand it?
Did you see the relevance of that example to your problem?

Feedback on any or all of these points would help us help you. Do not ignore help given and ask the same question again.

it did not help because my motor is off than turns on in 5 seconds turns of in another 5 seconds and repeats this. I want the motor to run for an amount than stop. I have wrote the code using that example. I see the relevance to my problem to some extent. I don t want it to turn on off. I want it to turn on right away and run for a period of time than turn off permanently.

const unsigned X_AXIS_PIN = 0;
const unsigned Y_AXIS_PIN = 1;
const unsigned Z_AXIS_PIN = 2;
const int motor1 = 3;
const int motor2 = 5;
const int motor3 = 10;
int motorState = LOW;
long previousMillis = 0;
long interval = 5000;


void setup() 
{
  Serial.begin(9600);
  pinMode(motor1, OUTPUT);
  pinMode(motor2, OUTPUT);
  pinMode(motor3, OUTPUT);

}

  int x,
      y,
      z;
      
void loop()
{
    Serial.print(analogRead(X_AXIS_PIN));
    Serial.print(" ");
    x = analogRead(X_AXIS_PIN);
    Serial.print(analogRead(Y_AXIS_PIN));
    Serial.print(" ");
    y = analogRead(Y_AXIS_PIN);
    Serial.println(analogRead(Z_AXIS_PIN));
    z = analogRead(Z_AXIS_PIN);
    delay(5000);
      
    if( x < 700 && y < 700 && z < 700)
     {
        unsigned long currentMillis = millis();
        if(currentMillis - previousMillis > interval) 
        previousMillis = currentMillis;
        if (motorState == LOW)
        motorState = HIGH;
        else
        motorState = LOW ;
        
        digitalWrite(motor1, motorState);
        digitalWrite(motor2, motorState);
        digitalWrite(motor3, motorState);
     }
     
     
}

If you do not want your motor ever to turn on again once it is off then you set the trigger time for being on to a value you can never reach. You could set it to zero and in the time test include the fact that the time to next event has not to be zero.

Interesting that you think you have written that code using the example, you haven't and there is a whopping big delay in it.
The essence of blink without delay is the without delay bit.

Also we are still waiting for you to modify that first post so the code is correctly within code tags.

If you want your motors to turn on and stay on for 25 minutes, and then turn off and continue with your code, you can do something like this:

const unsigned X_AXIS_PIN = 0;
const unsigned Y_AXIS_PIN = 1;
const unsigned Z_AXIS_PIN = 2;
const int motor1 = 3;
const int motor2 = 5;
const int motor3 = 10;
int motorState = LOW;
long delay25minutes = 1500000;    // delay for 25 minutes, which is 1500 seconds

void setup() 
{
  Serial.begin(9600);
  pinMode(motor1, OUTPUT);
  pinMode(motor2, OUTPUT);
  pinMode(motor3, OUTPUT);
}

  int x,
      y,
      z;
      
void loop()
{
    Serial.print(analogRead(X_AXIS_PIN));
    Serial.print(" ");
    x = analogRead(X_AXIS_PIN);
    Serial.print(analogRead(Y_AXIS_PIN));
    Serial.print(" ");
    y = analogRead(Y_AXIS_PIN);
    Serial.println(analogRead(Z_AXIS_PIN));
    z = analogRead(Z_AXIS_PIN);
    delay(5000);
      
    if( x < 700 && y < 700 && z < 700)
     {
        if (motorState == LOW)
        motorState = HIGH;
        else
        motorState = LOW ;
        
        digitalWrite(motor1, motorState);
        digitalWrite(motor2, motorState);
        digitalWrite(motor3, motorState);
        delay(delay25minutes);

        motorState = LOW;
        digitalWrite(motor1, motorState);
        digitalWrite(motor2, motorState);
        digitalWrite(motor3, motorState);
     }
     
     
}

If you want your Arduino to be doing some other code during the 25 minutes, then you need the blink without delay approach.

well i solved my problem i give thanks to AWOL's example. It introduced me to millis() function. I figured how can I use it to solve my problem. The device is running as intended it to.

thanks for the help dannii, but i found another solution using millis()

@ koningice,
Please share the code you used. I also struggle with the limited advice given. I find it much easier to see the whole sketch then analyse it.
I am interested in these types of timers.