Arduino UNO only works with usb cable

|Arduino Uno|
This is my OBSTACLE AVOIDING ROBOT (ARDUINO) project and its not working on 9V Battery

int trig=7 , echo=2 , sag_i=8 , sag_g=9 , sol_i=11 , sol_g=12 ;
int sure , mesafe ;
 void setup() {
  pinMode(trig,OUTPUT);
  pinMode(echo,INPUT);

  pinMode(sag_i,OUTPUT);
  pinMode(sag_g,OUTPUT);
  pinMode(sol_i,OUTPUT);
  pinMode(sol_g,OUTPUT);
  Serial.begin(9600);
int sure=0;
int mesafe=0;
 }

void loop(){
  delay(500);
  digitalWrite(trig,HIGH);
delayMicroseconds(1000);
digitalWrite(trig,LOW);
sure=pulseIn(echo,HIGH);
mesafe=(sure/2)/28.5;
Serial.println(mesafe);
if(mesafe<10){
digitalWrite(sol_i,HIGH);
digitalWrite(sol_g,LOW);
digitalWrite(sag_i,LOW);
digitalWrite(sag_g,HIGH);

delay(1000);

digitalWrite(sol_i,LOW);
digitalWrite(sol_g,LOW);
digitalWrite(sag_i,LOW);
digitalWrite(sag_g,LOW);
delay(500);
}
else{
digitalWrite(sag_i,HIGH);
digitalWrite(sag_g,LOW);
digitalWrite(sol_i,HIGH);
digitalWrite(sol_g,LOW);
delay(100);
}
  
}

It always in İf .
But it works with USB Cable Any Help ?

Well, clearly, there is nothing wrong with the code and there is no point in looking at it, but you can bet there is everything wrong with the battery, which is almost certainly a PP3. You are sending a boy on a man's job and you need a mans's battery. So put the PP3 back in the smoke detector you stole it from and try 6xAAs or perhaps 2x 18650s. or maybe your robot has some decent power available.

int sure=0;
int mesafe=0;
 }

It doesn't seem sensible to define variables you never use, just before they go out of scope.
The globals with the same names are automatically zeroed before setup() executes.