# Speed Control of 2 Motors with L298N

**URL:** <https://forum.arduino.cc/t/speed-control-of-2-motors-with-l298n/1245772>\
**Category:** Motors, Mechanics, Power and CNC\
**Created:** [April 9, 2024, 3:43pm UTC](https://forum.arduino.cc/t/speed-control-of-2-motors-with-l298n/1245772 "2024-04-09T15:43:25Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![pepemtnez87](https://avatars.discourse-cdn.com/v4/letter/p/ac8455/32.png) [@pepemtnez87](https://forum.arduino.cc/u/pepemtnez87)\
**Post date:** [April 9, 2024, 3:43pm UTC](https://forum.arduino.cc/t/speed-control-of-2-motors-with-l298n/1245772/1 "2024-04-09T15:43:25Z")

</div>

Hello. I'm working on a project which involves building a car with two DC motors. I'm controlling their speed through the L298N driver, but when I put it into operation, one of the wheels spins faster than the other and the car doesn't go straight.

I've been taking measurements and I see that it provides different voltage and current through the connection pins to the motor cables (OUT1, OUT2, OUT3, and OUT4). I suppose this is why the motors aren't spinning at the same speed.

I'm not sure what could be causing this. I'm powering the L298N with a regular 9V battery, and the Arduino with the 5V output from the driver. Can anyone help me?

---

<div class="post-metadata">

**Author:** ![hallowed31](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/hallowed31/32/1093680_2.png) [@hallowed31](https://forum.arduino.cc/u/hallowed31)\
**Post date:** [April 9, 2024, 3:45pm UTC](https://forum.arduino.cc/t/speed-control-of-2-motors-with-l298n/1245772/2 "2024-04-09T15:45:31Z")

</div>

Not without seeing the code. Nobody can help without that, at least. Don't forget to use code tags, please. Also, details about your circuit, a drawing is helpful, the more detail you give, the better help we can give. Are they straight DC motors? Identical? Gearboxes?

---

<div class="post-metadata">

**Author:** ![Railroader](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/railroader/32/274550_2.png) [@Railroader](https://forum.arduino.cc/u/Railroader)\
**Post date:** [April 9, 2024, 4:01pm UTC](https://forum.arduino.cc/t/speed-control-of-2-motors-with-l298n/1245772/3 "2024-04-09T16:01:59Z")

</div>

> [@pepemtnez87](#):
>
> one of the wheels spins faster than the other

That's normal for none precision motors.

---

<div class="post-metadata">

**Author:** ![GolamMostafa](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/golammostafa/32/239011_2.png) [@GolamMostafa](https://forum.arduino.cc/u/GolamMostafa)\
**Post date:** [April 9, 2024, 4:58pm UTC](https://forum.arduino.cc/t/speed-control-of-2-motors-with-l298n/1245772/4 "2024-04-09T16:58:43Z")

</div>

**1.** Check that your Motors' wirings are similar to the following (Fig-1):

 ![L298Uno](https://europe1.discourse-cdn.com/arduino/original/4X/7/a/a/7aa710d7285c1a96cee8ac8e0e11c8e953657846.png)  
Figure-1:

**2.** Check that your codes comply with the following Truth Table (Figure-2):  
 ![L298DriverTruth](https://europe1.discourse-cdn.com/arduino/original/4X/b/d/9/bd94612e37c28355b45761153bbb6728451c1151.png)  
Figure-2:

---

<div class="post-metadata">

**Author:** ![pepemtnez87](https://avatars.discourse-cdn.com/v4/letter/p/ac8455/32.png) [@pepemtnez87](https://forum.arduino.cc/u/pepemtnez87)\
**Post date:** [April 9, 2024, 6:20pm UTC](https://forum.arduino.cc/t/speed-control-of-2-motors-with-l298n/1245772/5 "2024-04-09T18:20:40Z")

</div>

Here is the code:

```arduino
//RIGHT MOTOR VARIABLES
int IN1 = 7;
int IN2 = 8;
int ENA = 9;
int PWM_RIGHT = 100;

//LEFT MOTOR VARIABLES
int IN3 = 12;
int IN4 = 13;
int ENB = 11;
int PWM_LEFT = 100;

void setup() {
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);
  pinMode(ENA, OUTPUT);
  pinMode(IN3, OUTPUT);
  pinMode(IN4, OUTPUT);
  pinMode(ENB, OUTPUT);
}

void loop() {
  //START RIGHT MOTOR FORWARD
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, HIGH);
  analogWrite(ENA, PWM_RIGHT);

  //START LEFT MOTOR FORWARD
  digitalWrite(IN3, LOW);
  digitalWrite(IN4, HIGH);
  analogWrite(ENB, PWM_LEFT);
}

```

And schematic drawing:

 ![Imagen](https://europe1.discourse-cdn.com/arduino/original/4X/3/b/6/3b646932d7881de15ea615dcb84a7f98c62c7f99.jpeg)

They are identical straight DC motors. I bought it by Amazon by this link:  
[https://www.amazon.es/gp/product/B096ZH5WQ6/ref=ppx\_yo\_dt\_b\_asin\_title\_o00\_s00?ie=UTF8&th=1](https://www.amazon.es/gp/product/B096ZH5WQ6/ref=ppx_yo_dt_b_asin_title_o00_s00?ie=UTF8&th=1)  
Here is a screenshot of the characteristics shown in Amazon:

 ![image](https://europe1.discourse-cdn.com/arduino/original/4X/0/a/2/0a26e084b3ba75bf4f0418d6754aeaebb3955088.jpeg)

Thank you for your help.

---

<div class="post-metadata">

**Author:** ![hallowed31](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/hallowed31/32/1093680_2.png) [@hallowed31](https://forum.arduino.cc/u/hallowed31)\
**Post date:** [April 9, 2024, 6:27pm UTC](https://forum.arduino.cc/t/speed-control-of-2-motors-with-l298n/1245772/7 "2024-04-09T18:27:09Z")

</div>

And the motors turn in the directions you want them to, just gradually veering to one side? I mean, by the drawing, they are wired identically. Without seeing it in person, if you reverse the wires on one of the motors does it make the problem better or worse?

---

<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:** [April 9, 2024, 7:13pm UTC](https://forum.arduino.cc/t/speed-control-of-2-motors-with-l298n/1245772/8 "2024-04-09T19:13:10Z")

</div>

That sounds like a classic 9V battery problem. They do not have the capacity to properly drive motors. Try an external power supply.

---

<div class="post-metadata">

**Author:** ![pepemtnez87](https://avatars.discourse-cdn.com/v4/letter/p/ac8455/32.png) [@pepemtnez87](https://forum.arduino.cc/u/pepemtnez87)\
**Post date:** [April 9, 2024, 8:14pm UTC](https://forum.arduino.cc/t/speed-control-of-2-motors-with-l298n/1245772/9 "2024-04-09T20:14:53Z")

</div>

its the same

---

<div class="post-metadata">

**Author:** ![pepemtnez87](https://avatars.discourse-cdn.com/v4/letter/p/ac8455/32.png) [@pepemtnez87](https://forum.arduino.cc/u/pepemtnez87)\
**Post date:** [April 9, 2024, 8:15pm UTC](https://forum.arduino.cc/t/speed-control-of-2-motors-with-l298n/1245772/10 "2024-04-09T20:15:40Z")

</div>

but what if I want it to be autonomous?

---

<div class="post-metadata">

**Author:** ![ruilviana](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ruilviana/32/722429_2.png) [@ruilviana](https://forum.arduino.cc/u/ruilviana)\
**Post date:** [April 9, 2024, 9:42pm UTC](https://forum.arduino.cc/t/speed-control-of-2-motors-with-l298n/1245772/11 "2024-04-09T21:42:41Z")

</div>

I understood that one of the engines turns faster than the other.  
Just to better understand, what happens if you reverse the connection of the motors.  
Connect the engine on the left where the one on the right is and the one on the right where the one on the left is.  
What happens?  
Does the higher speed change with the engine or not?

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [October 6, 2024, 9:43pm UTC](https://forum.arduino.cc/t/speed-control-of-2-motors-with-l298n/1245772/12 "2024-10-06T21:43:22Z")

</div>

Closed on October 6, 2024, 9:43pm UTC

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