Motor speed difference using L298n motor driver

I am making a line following robot using Arduino uno and L298n motor driver however there is a significant speed difference between the 2 motors. i know that it isn't simply because of the motors because ive used 3 sets of motors and the different remains the same always in the right motor even if i swap the left and right motors ive used 3 different motor drivers and the difference remains the same. I also ruled out the Arduino being defective as i used a separate Arduino uno and it still has the same problem. additional information even if i set the pwm speed of my left motors to 0 it still spins and spins faster than the right motor with pwm speed of 100.

My pin setup for the motor driver is
Ena 6
In1 7
In2 8
In3 9
In4 10
Enb 11

I also tried using different pin setup to no avail

Essential information (code...) is missing.

Motor speed is not directly related to PWM.

For informed help, please read and follow the instructions in the "How to get the best out of this forum" post, linked at the head of every forum category.

2 Likes

What does this indicate, put it in schematic form that should only take a few moments.

I'm sorry here is a copy of my code

#define Motor_SpeedA 6
#define M_A1 7 // Renamed MTR_A1 to M_A1
#define M_A2 8   // Renamed MTR_A2 to M_A2

#define Motor_SpeedB 11
#define M_B1 9   // Renamed MTR_B1 to M_B12q
#define M_B2 10   // Renamed MTR_B2 to M_B2 

#define OLS A0
#define ILS A1
#define MS A2
#define IRS A3                                                          
#define ORS A4

void setup() {
  pinMode(Motor_SpeedA, OUTPUT);
  pinMode(M_A1, OUTPUT);  // Updated MTR_A1 to M_A1
  pinMode(M_A2, OUTPUT);  // Updated MTR_A2 to M_A2
  
  pinMode(Motor_SpeedB, OUTPUT);
  pinMode(M_B1, OUTPUT);  // Updated MTR_B1 to M_B1
  pinMode(M_B2, OUTPUT);  // Updated MTR_B2 to M_B2

  pinMode(OLS, INPUT);
  pinMode(ILS, INPUT);
  pinMode(MS, INPUT);
  pinMode(IRS, INPUT);
  pinMode(ORS, INPUT);

  Serial.begin(9600);
}

void loop() {
  if (digitalRead(OLS) == 0 && digitalRead(ILS) == 0 && digitalRead(MS) == 0 && digitalRead(IRS) == 0 && digitalRead(ORS) == 0){
    Forward();
  }
  else if (digitalRead(OLS) == 1 && digitalRead(ILS) == 1 && digitalRead(MS) == 1 && digitalRead(IRS) == 1 && digitalRead(ORS) == 1){
    Backward();
  }
  else if (digitalRead(OLS) == 1 && digitalRead(ILS) == 1 && digitalRead(MS) == 0 && digitalRead(IRS) == 1 && digitalRead(ORS) == 1){
    Forward();
  }
  else if (digitalRead(OLS) == 0 && digitalRead(ILS) == 1 && digitalRead(MS) == 1 && digitalRead(IRS) == 1 && digitalRead(ORS) == 1){
    hardLeft();
  }
  else if (digitalRead(OLS) == 1 && digitalRead(ILS) == 0 && digitalRead(MS) == 1 && digitalRead(IRS) == 1 && digitalRead(ORS) == 1){
    softLeft();
  }
  else if (digitalRead(OLS) == 1 && digitalRead(ILS) == 0 && digitalRead(MS) == 0 && digitalRead(IRS) == 1 && digitalRead(ORS) == 1){
    turnLeft();
  }
  else if (digitalRead(OLS) == 0 && digitalRead(ILS) == 0 && digitalRead(MS) == 1 && digitalRead(IRS) == 1 && digitalRead(ORS) == 1){
    turnLeft();
  }
  else if (digitalRead(OLS) == 0 && digitalRead(ILS) == 0 && digitalRead(MS) == 0 && digitalRead(IRS) == 1 && digitalRead(ORS) == 1){
    hardLeft();
  }
  else if (digitalRead(OLS) == 1 && digitalRead(ILS) == 1 && digitalRead(MS) == 0 && digitalRead(IRS) == 0 && digitalRead(ORS) == 0){
    hardRight();
  }
  else if (digitalRead(OLS) == 1 && digitalRead(ILS) == 0 && digitalRead(MS) == 0 && digitalRead(IRS) == 1 && digitalRead(ORS) == 1){
    turnLeft();
  }
  else if (digitalRead(OLS) == 0 && digitalRead(ILS) == 0 && digitalRead(MS) == 0 && digitalRead(IRS) == 0 && digitalRead(ORS) == 1){
    hardLeft();
  }
  else if (digitalRead(OLS) == 0 && digitalRead(ILS) == 1 && digitalRead(MS) == 1 && digitalRead(IRS) == 1 && digitalRead(ORS) == 1){
    hardLeft();
  }
  else if (digitalRead(OLS) == 1 && digitalRead(ILS) == 0 && digitalRead(MS) == 0 && digitalRead(IRS) == 0 && digitalRead(ORS) == 0){
    hardRight();
  }
  else if (digitalRead(OLS) == 1 && digitalRead(ILS) == 1 && digitalRead(MS) == 1 && digitalRead(IRS) == 1 && digitalRead(ORS) == 0){
    hardRight();
  }
  else if (digitalRead(OLS) == 1 && digitalRead(ILS) == 1 && digitalRead(MS) == 1 && digitalRead(IRS) == 0 && digitalRead(ORS) == 1){
    softRight();
  }
  else if (digitalRead(OLS) == 1 && digitalRead(ILS) == 1 && digitalRead(MS) == 0 && digitalRead(IRS) == 0 && digitalRead(ORS) == 1){
    turnRight();
  }
  else if (digitalRead(OLS) == 1 && digitalRead(ILS) == 1 && digitalRead(MS) == 0 && digitalRead(IRS) == 0 && digitalRead(ORS) == 0){
    hardRight();
  }
  else if (digitalRead(OLS) == 1 && digitalRead(ILS) == 1 && digitalRead(MS) == 1 && digitalRead(IRS) == 0 && digitalRead(ORS) == 0){
    turnRight();
  }
  else if (digitalRead(OLS) == 1 && digitalRead(ILS) == 1 && digitalRead(MS) == 1 && digitalRead(IRS) == 1 && digitalRead(ORS) == 1){
    Backward();
  }
  else {
    Stop();
  }
}

//motor b left motor a right
void Forward() {
  analogWrite(Motor_SpeedA, 255);
  analogWrite(Motor_SpeedB, 255);
  digitalWrite(M_A1, LOW);//
  digitalWrite(M_A2, HIGH);
  digitalWrite(M_B1, HIGH);
  digitalWrite(M_B2, LOW);
}

void turnLeft() {
  analogWrite(Motor_SpeedA, 255);
  analogWrite(Motor_SpeedB, 0);
  digitalWrite(M_A1, HIGH);
  digitalWrite(M_A2, LOW);
  digitalWrite(M_B1, LOW);
  digitalWrite(M_B2, LOW);
}

void turnRight() {
  analogWrite(Motor_SpeedA, 200);
  analogWrite(Motor_SpeedB, 255);
  digitalWrite(M_A1, LOW);
  digitalWrite(M_A2, LOW);
  digitalWrite(M_B1, HIGH);
  digitalWrite(M_B2, LOW);
}

void Backward() {
  analogWrite(Motor_SpeedA, 50);
  analogWrite(Motor_SpeedB, 0);
  digitalWrite(M_A1, LOW);
  digitalWrite(M_A2, HIGH);
  digitalWrite(M_B1, LOW);
  digitalWrite(M_B2, HIGH);
}

void hardLeft() {
  analogWrite(Motor_SpeedA, 255);
  analogWrite(Motor_SpeedB, 255);
  digitalWrite(M_A1, LOW);
  digitalWrite(M_A2, HIGH);
  digitalWrite(M_B1, LOW);
  digitalWrite(M_B2, HIGH);
}

void hardRight() {
  analogWrite(Motor_SpeedA, 255);
  analogWrite(Motor_SpeedB, 255);
  digitalWrite(M_A1, HIGH);
  digitalWrite(M_A2, LOW);
  digitalWrite(M_B1, HIGH);
  digitalWrite(M_B2, LOW);
}

void softLeft() {
  analogWrite(Motor_SpeedA, 255);
  analogWrite(Motor_SpeedB, 0);
  digitalWrite(M_A1, LOW);//
  digitalWrite(M_A2, HIGH);
  digitalWrite(M_B1, LOW);
  digitalWrite(M_B2, LOW);
}

void softRight() {
  analogWrite(Motor_SpeedA, 0);
  analogWrite(Motor_SpeedB, 250);
  digitalWrite(M_A1, LOW);//
  digitalWrite(M_A2, LOW);
  digitalWrite(M_B1, HIGH);
  digitalWrite(M_B2, LOW);
}

void Stop() {
  digitalWrite(M_A1, LOW);
  digitalWrite(M_A2, LOW);
  digitalWrite(M_B1, LOW);
  digitalWrite(M_B2, LOW);
}

What's the nominal motor voltage and current, and the driver supply voltage provided by which device?

Try using pin 3 instead of pin 6 for Motor_SpeedA

The device is powered by a 11.1v 2000 mAh lipo battery

Sorry it doesn't work the other motor is still significantly faster

Do you have the jumpers removed from the enable pins on the L298 and are the Ena, Enb wires connected to the correct L298 pins?

I haven't removed anything and yes the wires are connected to the right pins im using this specific motor driver

We have no reason to believe you.

Post a wiring diagram, links to the product pages of all the parts and a clear, focused, close up photo of your setup.

1 Like

I noticed that in backwards, the motors have different speeds

Also left and right are different but not oppsite, one is 255,0 the other is 200,255

The speeds in backwards is different as an attempt to compensate for the huge speed difference and in the left and right i have yet to set those speeds im focusing on resolving the motor speed difference by testing in in the backwards command

Will a hand drawn wiring diagram do? I don't know how to make a wiring diagram using softwares

Hand drawn is preferred. Tutorial here: How to Read a Schematic - SparkFun Learn

Poor soldering can also cause problems. If you soldered joints, post a close up, focused picture showing those.



I am almost certain that soldering isn't the issues ive tried 3 different sets motors and same kind of problem

The soldering is a mess, and you may have overheated the plastic motor endplate supporting the brushes, causing them to be misaligned.

I swapped the motors putting the left motor on the right side and vice versa but its always the motor in right having less power i don't think soldering would explain that problem

I cannot reconcile that statement with this

1 Like