# Help needed with controlling DC motors with the L298N

**URL:** <https://forum.arduino.cc/t/help-needed-with-controlling-dc-motors-with-the-l298n/1345562>\
**Category:** General Guidance\
**Created:** [January 22, 2025, 9:40am UTC](https://forum.arduino.cc/t/help-needed-with-controlling-dc-motors-with-the-l298n/1345562 "2025-01-22T09:40:50Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![kaulsay](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/kaulsay/32/1178798_2.png) [@kaulsay](https://forum.arduino.cc/u/kaulsay)\
**Post date:** [January 22, 2025, 9:40am UTC](https://forum.arduino.cc/t/help-needed-with-controlling-dc-motors-with-the-l298n/1345562/1 "2025-01-22T09:40:50Z")

</div>

Trying to run two DC motors whose ends are connected to 2 wheels, with the L298N motor driver, but dont have an external power supply, so I connected a 12V AC to DC adapter to the barrel plug of my Arduino Mega 2560 R3, and connected 2 wires from the 5V and GND pins of the arduino, to the 5V and GND of the L298N.

Diagram of the setup and code is attached as below.

What am I doing wrong? I don't really have alot of microcontroller experience and this is the start of a university project.

 ![20250122_173552](https://europe1.discourse-cdn.com/arduino/original/4X/9/1/6/9168467959784bcb7e298e37bfcbacaee4e6fcba.jpeg)

```arduino
//motor without speed control test

int motor1pin1 = 3;
int motor1pin2 = 4;

int motor2pin1 = 5;
int motor2pin2 = 6;

void setup() {
  // put your setup code here, to run once:
  pinMode(motor1pin1, OUTPUT);
  pinMode(motor1pin2, OUTPUT);
  pinMode(motor2pin1, OUTPUT);
  pinMode(motor2pin2, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:   
  digitalWrite(motor1pin1, HIGH);
  digitalWrite(motor1pin2, LOW); //rotate in 1 direction -a

  digitalWrite(motor2pin1, HIGH);
  digitalWrite(motor2pin2, LOW); //rotate in 1 direction -b
  delay(1000);  

  digitalWrite(motor1pin1, LOW);
  digitalWrite(motor1pin2, HIGH); //rotate in direction opposite to a

  digitalWrite(motor2pin1, LOW);
  digitalWrite(motor2pin2, HIGH); //rotate in direction opposite to b
  delay(1000);
}

```

---

<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 22, 2025, 9:54am UTC](https://forum.arduino.cc/t/help-needed-with-controlling-dc-motors-with-the-l298n/1345562/2 "2025-01-22T09:54:23Z")

</div>

> [@kaulsay](#):
>
> What am I doing wrong?

You cannot power two motors from the 5V output pin. You will eventually burn out the MEGA

> but dont have an external power supply

You need one

---

<div class="post-metadata">

**Author:** ![kaulsay](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/kaulsay/32/1178798_2.png) [@kaulsay](https://forum.arduino.cc/u/kaulsay)\
**Post date:** [January 22, 2025, 10:56am UTC](https://forum.arduino.cc/t/help-needed-with-controlling-dc-motors-with-the-l298n/1345562/3 "2025-01-22T10:56:59Z")

</div>

Thank you for your reply.  
May I know why using an external power supply to the motor controller, and passing 12V to the mega and connecting the 5V pins on the mega and motor controller together not the same thing?

---

<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 22, 2025, 11:09am UTC](https://forum.arduino.cc/t/help-needed-with-controlling-dc-motors-with-the-l298n/1345562/4 "2025-01-22T11:09:42Z")

</div>

First I did not say to connect a 12V supply the the motor driver board, that would be way too much voltage for the motors.

It is different because the 5V output of the Arduino cannot supply enough Current to drive the motors. So you need a separate power supply that can supply enough current for the motors.

The driver board will decrease the voltage to the motors by up to 2V. A 6V, 2A supply will be OK but the motors may run a little slower.  
Most people use a 2S Li-ion battery which is perfect.

---

<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 22, 2025, 1:45pm UTC](https://forum.arduino.cc/t/help-needed-with-controlling-dc-motors-with-the-l298n/1345562/5 "2025-01-22T13:45:02Z")

</div>

This is a good tutorial

> **[L298n Motor driver Arduino | Motors | Motor Driver | L298n](https://projecthub.arduino.cc/lakshyajhalani56/l298n-motor-driver-arduino-motors-motor-driver-l298n-7e1b3b)**
>
> Here, We will learn "How to use L298n Motor Driver with Arduino Uno". Also We will control the Speed & Direction of Motor.

---

<div class="post-metadata">

**Author:** ![xfpd](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/xfpd/32/1120236_2.png) [@xfpd](https://forum.arduino.cc/u/xfpd)\
**Post date:** [January 22, 2025, 6:57pm UTC](https://forum.arduino.cc/t/help-needed-with-controlling-dc-motors-with-the-l298n/1345562/6 "2025-01-22T18:57:56Z")

</div>

See next post. Striking this post.  
~~If you supply power to the L298N from the 12vdc power supply, and you insert the "regulator" jumper, you can supply power to the Arduino from the L298N's 5v output (you are using that pin as an input).  
 ~~

 ![L298N-Module-Pinout](https://europe1.discourse-cdn.com/arduino/original/4X/c/6/2/c6246589766f0aea92b878c390bd121d2e2834e7.jpeg)

---

<div class="post-metadata">

**Author:** ![xfpd](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/xfpd/32/1120236_2.png) [@xfpd](https://forum.arduino.cc/u/xfpd)\
**Post date:** [January 22, 2025, 7:51pm UTC](https://forum.arduino.cc/t/help-needed-with-controlling-dc-motors-with-the-l298n/1345562/8 "2025-01-22T19:51:52Z")

</div>

I will agree, and strike my post. I neglected to recognize the motors as 6v motors. I measured my power supply and it shows 8 vdc.

---

<div class="post-metadata">

**Author:** ![PaulRB](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/paulrb/32/216330_2.png) [@PaulRB](https://forum.arduino.cc/u/PaulRB)\
**Post date:** [January 22, 2025, 10:02pm UTC](https://forum.arduino.cc/t/help-needed-with-controlling-dc-motors-with-the-l298n/1345562/9 "2025-01-22T22:02:44Z")

</div>

I already deleted my post because I assumed all these motors had max 6V, but it seems some can take 3V to 12V. We do not know what motors @kaulsay has.

---

<div class="post-metadata">

**Author:** ![TomGeorge](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/tomgeorge/32/215261_2.png) [@TomGeorge](https://forum.arduino.cc/u/TomGeorge)\
**Post date:** [January 22, 2025, 10:08pm UTC](https://forum.arduino.cc/t/help-needed-with-controlling-dc-motors-with-the-l298n/1345562/10 "2025-01-22T22:08:38Z")

</div>

Hi, @kaulsay  
Welcome to the forum.

> [@kaulsay](#):
>
> Diagram of the setup and code is attached as below.

Can you please post a copy of your circuit, a picture of a hand drawn circuit in jpg, png?  
Hand drawn and photographed is perfectly acceptable.  
Please include ALL hardware, power supplies, component names and pin labels.

Thanks.. Tom.. 😃 👍 ☕ 🇦🇺

---

<div class="post-metadata">

**Author:** ![kaulsay](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/kaulsay/32/1178798_2.png) [@kaulsay](https://forum.arduino.cc/u/kaulsay)\
**Post date:** [January 23, 2025, 1:54am UTC](https://forum.arduino.cc/t/help-needed-with-controlling-dc-motors-with-the-l298n/1345562/11 "2025-01-23T01:54:58Z")

</div>

![20250123_095140](https://europe1.discourse-cdn.com/arduino/original/4X/2/0/5/205a6900e9025895953fabb128fb29cc2a0b33f6.jpeg)

---

<div class="post-metadata">

**Author:** ![kaulsay](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/kaulsay/32/1178798_2.png) [@kaulsay](https://forum.arduino.cc/u/kaulsay)\
**Post date:** [January 23, 2025, 1:55am UTC](https://forum.arduino.cc/t/help-needed-with-controlling-dc-motors-with-the-l298n/1345562/12 "2025-01-23T01:55:45Z")

</div>

They are DC brush motors with an operating voltage of 3V to 6V.

---

<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 23, 2025, 1:59am UTC](https://forum.arduino.cc/t/help-needed-with-controlling-dc-motors-with-the-l298n/1345562/13 "2025-01-23T01:59:18Z")

</div>

Do NOT use the Arduino 5V output to power motors. That can damage the Arduino, or cause it to malfunction.

> [@kaulsay](#):
>
> They are DC brush motors with an operating voltage of 3V to 6V.

That is the nominal voltage range, and it is OK to exceed that, especially if you use PWM to control the motor speed.

Apply 12V to the driver motor input. Keep in mind that up to about 4V is wasted as heat in the ancient, very inefficient L298 driver, so the full 12V is never applied to the motors.

---

<div class="post-metadata">

**Author:** ![JCA34F](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jca34f/32/340148_2.png) [@JCA34F](https://forum.arduino.cc/u/JCA34F)\
**Post date:** [January 23, 2025, 4:11am UTC](https://forum.arduino.cc/t/help-needed-with-controlling-dc-motors-with-the-l298n/1345562/14 "2025-01-23T04:11:34Z")

</div>

After dropping 7V (12 - 5), the Arduino's 5 volt regulator can only supply about 175mA without overheating and shutting down or burning out.

---

<div class="post-metadata">

**Author:** ![DaveX](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/davex/32/751443_2.png) [@DaveX](https://forum.arduino.cc/u/DaveX)\
**Post date:** [January 23, 2025, 4:45am UTC](https://forum.arduino.cc/t/help-needed-with-controlling-dc-motors-with-the-l298n/1345562/15 "2025-01-23T04:45:22Z")

</div>

Wouldn't it work to put 12V on the module's input, use the module's 7805 to get 5V, then waste another 2V through the L298N, and deliver 3V to the motors at the bottom end of their 3-6V range?

Or use a different power supply:

> [@9v external power + 3-6v dc motors?](https://forum.arduino.cc/t/9v-external-power-3-6v-dc-motors/1219835/14):
>
> So you have 3 options, the 9V alkaline, 4AA and 6AA The L293 will drop the voltage maybe 2V so with the 4AAs the motor will see 4V, with 6AA it will see 7V. The 4V is within the motor specification the 7V is a little high but shouldn't hurt. Of course with 7V it will run faster. The 6AA will last the longest, the 4AA next and the 9V the shortest

---

<div class="post-metadata">

**Author:** ![TomGeorge](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/tomgeorge/32/215261_2.png) [@TomGeorge](https://forum.arduino.cc/u/TomGeorge)\
**Post date:** [January 23, 2025, 5:41am UTC](https://forum.arduino.cc/t/help-needed-with-controlling-dc-motors-with-the-l298n/1345562/16 "2025-01-23T05:41:45Z")

</div>

> [@DaveX](#):
>
> Wouldn't it work to put 12V on the module's input, use the module's 7805 to get 5V, then waste another 2V through the L298N, and deliver 3V to the motors at the bottom end of their 3-6V range?

I think you will find that Vcc = 12V is the supply directly to the L298 for motor supply, so 12 - 2 = 10V to the motors.

 ![298](https://europe1.discourse-cdn.com/arduino/original/4X/7/1/3/7133a8557d77790b7ff62461ffbd815c5ff90fbf.jpeg)

Tom.. 😃 👍 ☕ 🇦🇺

---

<div class="post-metadata">

**Author:** ![PaulRB](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/paulrb/32/216330_2.png) [@PaulRB](https://forum.arduino.cc/u/PaulRB)\
**Post date:** [January 23, 2025, 6:50am UTC](https://forum.arduino.cc/t/help-needed-with-controlling-dc-motors-with-the-l298n/1345562/17 "2025-01-23T06:50:58Z")

</div>

In that case here is the post I deleted before:

The motors are not powered from the module's 5V regulator. If they were, that regulator would burn out almost as quickly as the Arduino's regulator would.

The L298 will drop around 2V, exposing those 6V motors to around 10V.

---

<div class="post-metadata">

**Author:** ![JCA34F](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jca34f/32/340148_2.png) [@JCA34F](https://forum.arduino.cc/u/JCA34F)\
**Post date:** [January 23, 2025, 7:02am UTC](https://forum.arduino.cc/t/help-needed-with-controlling-dc-motors-with-the-l298n/1345562/18 "2025-01-23T07:02:35Z")

</div>

Power the L298 module with 12V and hold the output voltage power down with PWM to the enable pins (ENA & ENB).

---

<div class="post-metadata">

**Author:** ![DaveX](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/davex/32/751443_2.png) [@DaveX](https://forum.arduino.cc/u/DaveX)\
**Post date:** [January 23, 2025, 7:12am UTC](https://forum.arduino.cc/t/help-needed-with-controlling-dc-motors-with-the-l298n/1345562/19 "2025-01-23T07:12:47Z")

</div>

Ah. That looks correct. I was mistaken in reading whatever module schematic I had googled up.

---

<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 23, 2025, 8:39am UTC](https://forum.arduino.cc/t/help-needed-with-controlling-dc-motors-with-the-l298n/1345562/20 "2025-01-23T08:39:36Z")

</div>

It quite clear from your photo how you have it connected the schematic was not necessary.  
However as I already pointed out it is wrong.  
Did you review the tutorial?

---

<div class="post-metadata">

**Author:** ![kaulsay](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/kaulsay/32/1178798_2.png) [@kaulsay](https://forum.arduino.cc/u/kaulsay)\
**Post date:** [January 23, 2025, 8:51am UTC](https://forum.arduino.cc/t/help-needed-with-controlling-dc-motors-with-the-l298n/1345562/21 "2025-01-23T08:51:50Z")

</div>

Yes, thank you

[Next page](https://forum.arduino.cc/t/help-needed-with-controlling-dc-motors-with-the-l298n/1345562.md?page=2)
