Activate a DC motor for a fixed amount of time
#include &lt;Wire.h&gt;
#include &lt;Adafruit_MotorShield.h&gt;
#include "utility/Adafruit_PWMServoDriver.h"

Adafruit_MotorShield AFMS = Adafruit_MotorShield(); 
Adafruit_DCMotor *myMotor = AFMS.getMotor(1);
boolean motorRunning = false;
unsigned long motorStartMillis;
unsigned long motorRunMillis = 180000;

void setup() {
   Serial.begin(9600);           // set up Serial library at 9600 bps
   AFMS.begin();  // create with the default frequency 1.6KHz
}

void loop() {
  IOvalue = 1000

  if (IOvalue = 1000) {
    //this is the motor I wish to run for 3 min 
    myMotor-&gt;setSpeed(25); 
    myMotor-&gt;run(FORWARD); 
    motorStartMillis = millis();
    motorRunning = true;
  }

  // check if motor is running and time-to-run has elapsed
  if( motorRunning &amp;&amp; (millis()-motorStartMillis &gt; motorRunMillis) )
  {
    myMotor-&gt;setSpeed(0); 
    myMotor-&gt;run(RELEASE);
    motorRunning = false;
  }
}