Ardunio Programm only works on usb, but not with battery

Hello,
i build a small robot using arduino nano, 2 servos and 3 ultra sonic sensors.
I want it to avoid obstacles, and right know everything works fine if i let the robot drive around attached to my laptop and an usb cable. But when i switch to battery, in my case its an 18650 Li-ion battery with 3.7V and i believe 3000mAh.
The steering is good and the delays are good timed with the usb cable.
When i attach the battery, the robot still avoid obstacles and move around like normal. if an obstacle is in front of it the robot waits some seconds. And to it did not drive backward, he just stops for some seconds and then turns and keep going.
I have no idea why its doing so, but i hope anyone of you can help me.

Here is my programm code, but i think it has nothing to do with the programm itself.

int triggerFront = 2;
int echoFront = 3;
int triggerRight = 4;
int echoRight = 5;
int triggerLeft = 6;
int echoLeft = 7;

int in1 = 8; //right engine
int in2 = 9; //right engine
int in3 = 10; //left engine
int in4 = 11; //left engine

int maxDistanceToObject = 18; //15cm max distance to any object
int distLeft = 0;
int distRight = 0;
String obstacle = ""; //latest detected obstacle -> front/left/right


void setup() {
  // put your setup code here, to run once:
  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);
  pinMode(in3, OUTPUT);
  pinMode(in4, OUTPUT);
  pinMode(triggerFront, OUTPUT);
  pinMode(triggerLeft, OUTPUT);
  pinMode(triggerRight, OUTPUT);
  pinMode(echoFront, INPUT);
  pinMode(echoLeft, INPUT);
  pinMode(echoRight, INPUT);
    
  Serial.begin(9600);
  Serial.println("Communication started..");
}

void loop() {/* MAIN LOOP */

 distLeft = getDistanceCM(triggerLeft, echoLeft);
 distRight = getDistanceCM(triggerRight, echoRight);
 
 if(distLeft < maxDistanceToObject) {
    _stop(in1, in2); //stop right engine
    obstacle = "left";
    delay(400); //wait until turned
  }

  if(distRight < maxDistanceToObject) {
    _stop(in3, in4);//stop left engine
    obstacle = "right";
    delay(400); //wait until turned
  }
  
  if(getDistanceCM(triggerFront, echoFront) < maxDistanceToObject) { //check front
    backward();
    obstacle = "front";
    delay(500); //drive back for 200ms

    if(distLeft > distRight) { //decide where to turn for smarter path
      //if left ist more place than right, turn left
      left();
      delay(400);
    }else{
      right();
      delay(400);
    }
  }else{
    if(obstacle = "") {
      forward();
    }
  }

  obstacle = ""; //reset obstacle variable
  delay(100); //important for working not at full power
}

/* FUNCTIONS */

void forward() {
  digitalWrite(in1, HIGH);
  digitalWrite(in2, LOW);
  digitalWrite(in3, HIGH);
  digitalWrite(in4, LOW);
}

void backward() {
  digitalWrite(in1, LOW);
  digitalWrite(in2, HIGH);
  digitalWrite(in3, LOW);
  digitalWrite(in4, HIGH);
}
void left() {
  digitalWrite(in1, HIGH);
  digitalWrite(in2, LOW);
  digitalWrite(in3, LOW);
  digitalWrite(in4, HIGH);
}
void right() {
  digitalWrite(in1, LOW);
  digitalWrite(in2, HIGH);
  digitalWrite(in3, HIGH);
  digitalWrite(in4, LOW);
}
void _stop(int in_a, int in_b) {
  digitalWrite(in_a, LOW);
  digitalWrite(in_b, LOW);
}
void _stopAll() {
  digitalWrite(in1, LOW);
  digitalWrite(in2, LOW);
  digitalWrite(in3, LOW);
  digitalWrite(in4, LOW);
}

float getDistanceCM(int trigger, int echo) {
  /** returns the distance to an object in centimeters, expect 2 parameter
   *  1. echo has to be the integer value of the input echo pin
   *  2. trigger has to be integer
   */
   
  float distance = 0;
  long timer = 0; 

  digitalWrite(trigger, LOW);
  delay(2);
  digitalWrite(trigger, HIGH); 
  delay(10); 
  digitalWrite(trigger, LOW);
  timer = pulseIn(echo, HIGH);
  timer = timer / 2; 
  distance = timer * 0.0343;
  Serial.println(distance);
  return distance;
}

PS: Sorry for bad english i am german.

Is it a single 18650 ?
How is the battery connected ? (schematic)

It is only one 18650 battery.
It is connected parralell to the 5V of the Nano and the 5V pins of the sensors and the vcc pin of the motor shield.
All + and - poles are one the breadboard on the side rails for + and -. From there everything is connected to GND and +5V.

I hope you could understand what i mean.

AT 3.7 volts I doubt there is enough voltage to operate all that you want.

An actual schematic would be needed to know for sure (even hand drawn).

Measure the voltage in all situations.

You need 5v for your project (certainly for the servos, probably for the sensor - and the micro itself would be just on the edge of it’s spec’ed voltage at 16mhz), 3.7 is not sufficient. Particularly if standby battery life isn’t important, you can use a cheap DC-DC step up converter (double-check the input and output voltage specs - there are 5v fixed ones that take 2-5v in, or 3-5v in, and make sure it’s one that goes up not down). Or use 2 cells in parallel and regulate it down with linear regulator (if current is low) or step down converter.

(step up converters are called boost converters, and step down converters are called buck converters - but for searching ebay, use step up/down, not buck/boost, because sellers include both buck and boost in the listings for both types of converters)