Go Down

Topic: [L298N] Motor stutters when under load but only in one direction (Read 1 time) previous topic - next topic

ljuborados

I am using the Arduino UNO with the L298N to control 2 DC motors in an RC car.
When the RC car is not on the ground (wheels are in the air) it is working without a single problem, but when the car is on the ground, everything is working for the first minute, after that the motors spin normally in one direction, but stutter in the other.
When motor terminals are switched, the same thing happens but in the other direction, so it shouldn't be the motors.
I am using L298N like in the picture:

 
Everything is powered from a 12V battery, Arduino and L298N are connected to the battery in parallel, the L298N has a onboard 5V regulator but only up to 12V on my version, so the regulator is switched off because last boards voltage regulator was fried from using the same battery (voltage is around 13.2V when fully charged), so Arduino is connected to the 5V input terminal on the board.

Here is the code:
Code: [Select]

 #include<SoftwareSerial.h>


 //HC05 soft serial
 const int rx = 5;
 const int tx = 6;

 SoftwareSerial mySerial (rx, tx);

//L298N spoj
  const int in1  = 13;
  const int in2  = 12;
  const int in3  = 8;
  const int in4  = 9;
  const int en1 = 11;
  const int en2 = 10;

//Useful Variables
  int i=0;
  int j=0;
  int state;
  int vSpeed=200;     // Default speed, from 0 to 255

void setup() {
    // Set pins as outputs:
    pinMode(in1, OUTPUT);
    pinMode(in2, OUTPUT);
    pinMode(in3, OUTPUT);
    pinMode(in4, OUTPUT);
    pinMode(en1, OUTPUT);
    pinMode(en2, OUTPUT);

    // Initialize serial communication at 9600 bits per second:
    mySerial.begin(115200);
}

void loop() {

  //Save income data to variable 'state'
    if(mySerial.available() > 0){
      state = mySerial.read();
    }

  switch(state) {

  /***********************Forward****************************/
  //If state is equal with letter 'F', car will go forward!
  case 'F' :
      analogWrite(en1, vSpeed);
      analogWrite(en2, vSpeed);
      digitalWrite(in1, HIGH);
      digitalWrite(in2, LOW);
      digitalWrite(in3, HIGH);
      digitalWrite(in4, LOW);
  break;
  /***********************Backward****************************/
  //If state is equal with letter 'B', car will go backward
  case 'B' :
      analogWrite(en1, vSpeed);
      analogWrite(en2, vSpeed);
      digitalWrite(in1, LOW);
      digitalWrite(in2, HIGH);
      digitalWrite(in3, LOW);
      digitalWrite(in4, HIGH);
  break;
  /************************Right****************************/
  //If state is equal with letter 'R', car will start turning right
  case 'R' :
      digitalWrite(in1, HIGH);
      digitalWrite(in2, LOW);
      digitalWrite(in3, LOW);
      digitalWrite(in4, HIGH);
  break;
  /************************Left*****************************/
  case 'L' :
      digitalWrite(in1, LOW);
      digitalWrite(in2, HIGH);
      digitalWrite(in3, HIGH);
      digitalWrite(in4, LOW);
  break;

  /************************Stop*****************************/
  //If state is equal with letter 'S', stop the car
  case 'S' :
      digitalWrite(in1, LOW);
      digitalWrite(in2, LOW);
      digitalWrite(in3, LOW);
      digitalWrite(in4, LOW);
  break;
}
}
}


Any help would be greatly appreciated!

JimboZA

I'm wondering if it's a current thing? What's the stall current of the motors, and is that within the 298's capability?

Apart from that, at higher currents (~2A iirc but check the datasheet) the 298 drops almost 5V of the motor voltage so you might not have enough left to drive the motors under load.



Johannesburg hams call me: ZS6JMB on Highveld rep 145.7875 (-600 & 88.5 tone)
Dr Perry Cox: "Help me to help you, help me to help you...."
Your answer may already be here: https://forum.arduino.cc/index.php?topic=384198.0

Southpark

See what happens if you reduce the motor voltage. If you use a bench power supply with a supply voltage that you can control -- could test your system by choosing a lower raw motor supply voltage for the L298N. This is to see if your L298n is getting maxed out in its max power handling...... and overheating after 1 minute or so.

Go Up