Stopping the dc motor

I have been tring to break a dc motors and i can’t achieve that with my sketch using the maxsonar. My dc motors are controlled by two different kind of sensers. The first is the linetracking senser which is controlling the speed if the vehicle is out of the track(out of the white line) and the second is the MaxSonar-EZ1LV which should break the dc motor if an object is near. My linetracker is working fine but the maxsonar can’t stop the motors! Am connecting the AN wire from maxsonar to the analog pin of my arduino and the power it with +5v and GRD it. Is my code below okey? or how should i wire the maxsonar/ interface it with arduino? Is there a way to test my maxsonar whether it okey?

//ROBOT DESIGN
// * by Mturuchiu

int maxPin1 = 0; // select the input pin for the maxsonar(range sensor)
int maxPin2 = 1;
int maxPin3 = 2;
int maxPin4 = 3;
int pwmmotor1 = 10;   // select the pin for motor1 pwm
int pwmmotor2 = 9;   // select the pin for motor2 pwm
int MOTOR1A = 2;
int MOTOR1B = 3;
int MOTOR2A = 4;
int MOTOR2B = 5;

int linetracker1 = 6; // Single line tracking sensor1
int linetracker2 = 7; // Single line tracking sensor2
int linevalue1;
int linevalue2;


int const_change_direction = 30;
int ENA = 8;
int val = 0; // variable to store the value coming from the sensor
int val0 = 0;
int val1 = 0;
int val2 = 0;
int valx = 0;

void setup() {
  beginSerial(9600);
  //pinMode(pwmmotor1, OUTPUT);  // declare the ledPin as an OUTPUT
  pinMode(MOTOR1A, OUTPUT);  // declare the MOTOR1A as an OUTPUT
  pinMode(MOTOR1B, OUTPUT);  // declare the MOTOR1B as an OUTPUT
  pinMode(MOTOR2A, OUTPUT);  // declare the MOTOR2A as an OUTPUT
  pinMode(MOTOR2B, OUTPUT);  // declare the MOTOR2B as an OUTPUT
   pinMode(ENA, OUTPUT);  // declare the ENA as an OUTPUT
}

void loop() {
 
 linevalue1 = digitalRead(linetracker1);
 linevalue2 = digitalRead(linetracker2);
 
 
  digitalWrite(MOTOR1A, LOW);
  digitalWrite(MOTOR1B, HIGH);
  digitalWrite(MOTOR2A, LOW);
  digitalWrite(MOTOR2B, HIGH);
        
          digitalWrite(ENA, HIGH);
  val = (analogRead(maxPin1)); // read the value from the sensor
  
 if ( val < 15 ){
 digitalWrite(MOTOR1A, HIGH);
 digitalWrite(MOTOR1B, HIGH);
 digitalWrite(MOTOR2A, HIGH);
  digitalWrite(MOTOR2B, HIGH);
  Serial.print("OBJECT CLOSE. ROBOT STOPPED!!!");
}
 
// val1 = val;
// val2 = val;
 valx = 100;
 val1 = valx;
 val2 = valx;
  if ( linevalue1 == 1 ){
  val1 = valx + const_change_direction;
  //valx = valx + const_change_direction;
   Serial.print("Changing right");
 }
 
   if ( linevalue2 == 1 ){
  val2 = valx + const_change_direction;
 // valx = valx + const_change_direction;
   Serial.print("Changing Left");
 }
   
  analogWrite(pwmmotor1, val2);
  analogWrite(pwmmotor2, val1);
  //Serial.print("R");
  //Serial.print(val2);
  
  //Serial.print("R");
  //Serial.print(val);
  delay(100);                  // stop the program for some time
}

Am using two dc motors and Pololu MD03A H-bridge motor driver.