# Motor speed difference using L298n motor driver

**URL:** <https://forum.arduino.cc/t/motor-speed-difference-using-l298n-motor-driver/1216635>\
**Category:** Robotics\
**Created:** [January 27, 2024, 4:18pm UTC](https://forum.arduino.cc/t/motor-speed-difference-using-l298n-motor-driver/1216635 "2024-01-27T16:18:34Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![tux\_da\_penguin](https://avatars.discourse-cdn.com/v4/letter/t/f1d935/32.png) [@tux\_da\_penguin](https://forum.arduino.cc/u/tux_da_penguin)\
**Post date:** [January 27, 2024, 4:18pm UTC](https://forum.arduino.cc/t/motor-speed-difference-using-l298n-motor-driver/1216635/1 "2024-01-27T16:18:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![DrDiettrich](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/drdiettrich/32/219048_2.png) [@DrDiettrich](https://forum.arduino.cc/u/DrDiettrich)\
**Post date:** [January 27, 2024, 4:33pm UTC](https://forum.arduino.cc/t/motor-speed-difference-using-l298n-motor-driver/1216635/2 "2024-01-27T16:33:23Z")

</div>

Essential information (code...) is missing.

Motor speed is not directly related to PWM.

---

<div class="post-metadata">

**Author:** ![anon94801460](https://avatars.discourse-cdn.com/v4/letter/a/278dde/32.png) [@anon94801460](https://forum.arduino.cc/u/anon94801460)\
**Post date:** [January 27, 2024, 4:42pm UTC](https://forum.arduino.cc/t/motor-speed-difference-using-l298n-motor-driver/1216635/3 "2024-01-27T16:42:47Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![gilshultz](https://avatars.discourse-cdn.com/v4/letter/g/67e7ee/32.png) [@gilshultz](https://forum.arduino.cc/u/gilshultz)\
**Post date:** [January 27, 2024, 4:56pm UTC](https://forum.arduino.cc/t/motor-speed-difference-using-l298n-motor-driver/1216635/4 "2024-01-27T16:56:16Z")

</div>

> [@tux\_da\_penguin](#):
>
> Ena 6  
> In1 7  
> In2 8  
> In3 9  
> In4 10  
> Enb 11

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

---

<div class="post-metadata">

**Author:** ![tux\_da\_penguin](https://avatars.discourse-cdn.com/v4/letter/t/f1d935/32.png) [@tux\_da\_penguin](https://forum.arduino.cc/u/tux_da_penguin)\
**Post date:** [January 27, 2024, 4:58pm UTC](https://forum.arduino.cc/t/motor-speed-difference-using-l298n-motor-driver/1216635/5 "2024-01-27T16:58:38Z")

</div>

I'm sorry here is a copy of my code

```arduino
#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);
}

```

---

<div class="post-metadata">

**Author:** ![DrDiettrich](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/drdiettrich/32/219048_2.png) [@DrDiettrich](https://forum.arduino.cc/u/DrDiettrich)\
**Post date:** [January 27, 2024, 5:09pm UTC](https://forum.arduino.cc/t/motor-speed-difference-using-l298n-motor-driver/1216635/6 "2024-01-27T17:09:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jim-p](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jim-p/32/922840_2.png) [@jim-p](https://forum.arduino.cc/u/jim-p)\
**Post date:** [January 27, 2024, 5:12pm UTC](https://forum.arduino.cc/t/motor-speed-difference-using-l298n-motor-driver/1216635/7 "2024-01-27T17:12:01Z")

</div>

Try using pin 3 instead of pin 6 for Motor\_SpeedA

---

<div class="post-metadata">

**Author:** ![tux\_da\_penguin](https://avatars.discourse-cdn.com/v4/letter/t/f1d935/32.png) [@tux\_da\_penguin](https://forum.arduino.cc/u/tux_da_penguin)\
**Post date:** [January 27, 2024, 5:12pm UTC](https://forum.arduino.cc/t/motor-speed-difference-using-l298n-motor-driver/1216635/8 "2024-01-27T17:12:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![tux\_da\_penguin](https://avatars.discourse-cdn.com/v4/letter/t/f1d935/32.png) [@tux\_da\_penguin](https://forum.arduino.cc/u/tux_da_penguin)\
**Post date:** [January 27, 2024, 5:17pm UTC](https://forum.arduino.cc/t/motor-speed-difference-using-l298n-motor-driver/1216635/9 "2024-01-27T17:17:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jim-p](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jim-p/32/922840_2.png) [@jim-p](https://forum.arduino.cc/u/jim-p)\
**Post date:** [January 27, 2024, 5:36pm UTC](https://forum.arduino.cc/t/motor-speed-difference-using-l298n-motor-driver/1216635/10 "2024-01-27T17:36:23Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![tux\_da\_penguin](https://avatars.discourse-cdn.com/v4/letter/t/f1d935/32.png) [@tux\_da\_penguin](https://forum.arduino.cc/u/tux_da_penguin)\
**Post date:** [January 27, 2024, 5:39pm UTC](https://forum.arduino.cc/t/motor-speed-difference-using-l298n-motor-driver/1216635/11 "2024-01-27T17:39:49Z")

</div>

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

 ![H0111c03b49c74f9ea66c9b74d12be3b8D.jpg_640x640Q90.jpg_](https://europe1.discourse-cdn.com/arduino/original/4X/2/8/7/287d88f867d6e955c7aa6a91ed3aea6037ba14c6.webp)

---

<div class="post-metadata">

**Author:** ![anon94801460](https://avatars.discourse-cdn.com/v4/letter/a/278dde/32.png) [@anon94801460](https://forum.arduino.cc/u/anon94801460)\
**Post date:** [January 27, 2024, 5:45pm UTC](https://forum.arduino.cc/t/motor-speed-difference-using-l298n-motor-driver/1216635/12 "2024-01-27T17:45:02Z")

</div>

> [@tux\_da\_penguin](#):
>
> yes the wires are connected to the right pins

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.

---

<div class="post-metadata">

**Author:** ![jim-p](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jim-p/32/922840_2.png) [@jim-p](https://forum.arduino.cc/u/jim-p)\
**Post date:** [January 27, 2024, 5:56pm UTC](https://forum.arduino.cc/t/motor-speed-difference-using-l298n-motor-driver/1216635/13 "2024-01-27T17:56:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![tux\_da\_penguin](https://avatars.discourse-cdn.com/v4/letter/t/f1d935/32.png) [@tux\_da\_penguin](https://forum.arduino.cc/u/tux_da_penguin)\
**Post date:** [January 27, 2024, 6:01pm UTC](https://forum.arduino.cc/t/motor-speed-difference-using-l298n-motor-driver/1216635/14 "2024-01-27T18:01:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![tux\_da\_penguin](https://avatars.discourse-cdn.com/v4/letter/t/f1d935/32.png) [@tux\_da\_penguin](https://forum.arduino.cc/u/tux_da_penguin)\
**Post date:** [January 27, 2024, 6:01pm UTC](https://forum.arduino.cc/t/motor-speed-difference-using-l298n-motor-driver/1216635/15 "2024-01-27T18:01:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![anon94801460](https://avatars.discourse-cdn.com/v4/letter/a/278dde/32.png) [@anon94801460](https://forum.arduino.cc/u/anon94801460)\
**Post date:** [January 27, 2024, 6:06pm UTC](https://forum.arduino.cc/t/motor-speed-difference-using-l298n-motor-driver/1216635/16 "2024-01-27T18:06:18Z")

</div>

Hand drawn is preferred. Tutorial here: [How to Read a Schematic - SparkFun Learn](https://learn.sparkfun.com/tutorials/how-to-read-a-schematic/all)

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

---

<div class="post-metadata">

**Author:** ![tux\_da\_penguin](https://avatars.discourse-cdn.com/v4/letter/t/f1d935/32.png) [@tux\_da\_penguin](https://forum.arduino.cc/u/tux_da_penguin)\
**Post date:** [January 28, 2024, 2:55am UTC](https://forum.arduino.cc/t/motor-speed-difference-using-l298n-motor-driver/1216635/17 "2024-01-28T02:55:12Z")

</div>

![IMG_20240128_104959](https://europe1.discourse-cdn.com/arduino/original/4X/b/f/8/bf885dfe300380a1b22c9adf66df78fd5cb46248.jpeg)  
 ![IMG_20240128_095011.HEIC](https://europe1.discourse-cdn.com/arduino/original/4X/5/9/5/59596403ba3aa48183249df67591717a87fcb563.jpeg)  
 ![IMG_20240128_094925.HEIC](https://europe1.discourse-cdn.com/arduino/original/4X/7/4/c/74c1d699ab99da0b9e7f2da3602f509cb44c6240.jpeg)

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

---

<div class="post-metadata">

**Author:** ![anon94801460](https://avatars.discourse-cdn.com/v4/letter/a/278dde/32.png) [@anon94801460](https://forum.arduino.cc/u/anon94801460)\
**Post date:** [January 28, 2024, 3:55am UTC](https://forum.arduino.cc/t/motor-speed-difference-using-l298n-motor-driver/1216635/18 "2024-01-28T03:55:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![tux\_da\_penguin](https://avatars.discourse-cdn.com/v4/letter/t/f1d935/32.png) [@tux\_da\_penguin](https://forum.arduino.cc/u/tux_da_penguin)\
**Post date:** [January 28, 2024, 4:41am UTC](https://forum.arduino.cc/t/motor-speed-difference-using-l298n-motor-driver/1216635/19 "2024-01-28T04:41:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [January 28, 2024, 7:23am UTC](https://forum.arduino.cc/t/motor-speed-difference-using-l298n-motor-driver/1216635/20 "2024-01-28T07:23:27Z")

</div>

> [@tux\_da\_penguin](#):
>
> I am almost certain that soldering isn't the issues

I cannot reconcile that statement with this

 ![image](https://europe1.discourse-cdn.com/arduino/original/4X/e/6/b/e6bdd8f60d564e97d4598b98b1349117885fe480.jpeg)

[Next page](https://forum.arduino.cc/t/motor-speed-difference-using-l298n-motor-driver/1216635.md?page=2)
