Controlling a DC motor using PWM and a potentiometer

Here. This is just about as useless as the original code, but will actually sort of do what you want. Because we don't know what the delays and the relays are for, it makes no sense. But this code will basically read the pot value, constrain it to between 90 and 255 (which will NEVER turn off the motor, btw.) Then the motor will run at the set speed for 250 milliseconds, stop running, do nothing for 250 milliseconds, then set a relay high, do nothing for another 250 milliseconds, and then repeat. The motor will never stop running except during those delays (500 milliseconds). You will not be able to shut this off unless you unplug it.

int pot = 0;
int relay = 3;
int motorPin = 11;  
int val = 0;

void setup()                    // run once, when the sketch starts
{
  //Serial.begin(9600);           // set up Serial library at 9600 bps
//  pinMode(pot, INPUT); //don't need this
  pinMode(relay, OUTPUT);
  pinMode(motorPin, OUTPUT);
}

void getPot() {
  val = analogRead(pot);
  constrain(val,90,255); //this restricts the analog value to between 90 and 255
}

void run() {

  analogWrite(motorPin, val); //this will run the motor at the speed set by the pot value
  delay(250); //no idea why you have a delay
  digitalWrite(motorPin, LOW); //but because you pull the motor pin low, it stops after 250 milliseconds here
  delay(250); //then you delay again ??
  digitalWrite(relay, HIGH); //then you set a relay (for what purpose?)
  delay(250); //then you delay again... no idea why
}


void loop()                     // run over and over again
{
  getpot(); //get the analog value
  run(); //run the motor

}