*VIDEO* Program react differently regards of POWER source - USB/BATTERY

Don't look at the commends, they are from the other code.
now i have this code and the same problem - soon i'll upload the video on youtube and show you.

void Explore(){

  long duration, distance;
  digitalWrite(trigPin, LOW);  // Added this line
  delayMicroseconds(2); // Added this line
  digitalWrite(trigPin, HIGH);
//  delayMicroseconds(1000); - Removed this line
  delayMicroseconds(10); // Added this line
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration/2) / 29.1;

  
  distance = (duration/2) / 29.1;

  
 if(distance>12 || distance<0){
    obstacle = false;
    advance (120,120); 
  }
  else{
    
    // too close, distance < 15 cm
    if(distance<=1){
      back_off (150,150);
    }
    else{
      
      obstacle = true;
      
      if(GetPosition() > GetMiddlePosition()){
        turn_R (200,200); 
        
        
        SetServoDirection(0);
      }
      else{
        turn_L (200,200);
     
        
        SetServoDirection(1);
      }
  }
}
}

I'm working on this like whole day and now night. I refresh this site every 10 minutes with hope that you adwise me.
VIDEO - - YouTube
THE code works only when i will upload it via usb. After i plug out and then again plug in, robot behave like on the beginning of the video