My arduino (using motor driver L298N) only run half a full routine

hi there, i have a weird problem where my arduino only run half of the full routine when I detached the usb from my laptop. it works fine when i attach the arduino my laptop. Can someone help me...

This the the tutorial that i followed

The only different thing that i didnt follow the tutorial is that i used arduino mega.

int in1 = 6;
int in2 = 5;
int enA = 7;

int in3 = 3;
int in4 = 4;
int enB = 2;
int dt = 100;
void setup() {
  // put your setup code here, to run once:
 pinMode(enA,OUTPUT);
 pinMode(in1,OUTPUT);
 pinMode(in2,OUTPUT);
 pinMode(enB,OUTPUT);
 pinMode(in3,OUTPUT);
 pinMode(in4,OUTPUT);

}

void loop() {
  // put your main code here, to run repeatedly:
// forward
digitalWrite(in1,HIGH);
digitalWrite(in2,LOW);
digitalWrite(in3,HIGH);
digitalWrite(in4,LOW);
digitalWrite(enA,100);
digitalWrite(enB,100);
delay(dt);

//TURN RIGHT
digitalWrite(in1,LOW);
digitalWrite(in2,HIGH);
digitalWrite(in3,HIGH);
digitalWrite(in4,LOW);
digitalWrite(enA,100);
digitalWrite(enB,100);
delay(dt);

//TURN LEFT
digitalWrite(in1,HIGH);
digitalWrite(in2,LOW);
digitalWrite(in3,LOW);
digitalWrite(in4,HIGH);
digitalWrite(enA,100);
digitalWrite(enB,100);
delay(dt);                                          //only works until this part and then the arduino restart.
                                                          //only when i detach the usb from the arduino

//backward
digitalWrite(in1,LOW);
digitalWrite(in2,HIGH);
digitalWrite(in3,LOW);
digitalWrite(in4,HIGH);
digitalWrite(enA,100);
digitalWrite(enB,100);
delay(dt);

//STOP
digitalWrite(in1,LOW);
digitalWrite(in2,LOW);
digitalWrite(in3,LOW);
digitalWrite(in4,LOW);
digitalWrite(enA,0);
digitalWrite(enB,0);
delay(dt);
}

this is my coding btw.

Errr. . . ?

(Please don't make me watch the "tutorial")

My equipment can't run Youtube videos.
What is "half of full routine" supposed to tell?
Schematics could be valuable...

Probably that the battery is too small.

Yes, it could be. One never knows....

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.