# DC Motors run when powered by an Arduino connected to a computer but not a battery

**URL:** <https://forum.arduino.cc/t/dc-motors-run-when-powered-by-an-arduino-connected-to-a-computer-but-not-a-battery/981541>\
**Category:** Motors, Mechanics, Power and CNC\
**Created:** [April 16, 2022, 7:00am UTC](https://forum.arduino.cc/t/dc-motors-run-when-powered-by-an-arduino-connected-to-a-computer-but-not-a-battery/981541 "2022-04-16T07:00:18Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![drycloud](https://avatars.discourse-cdn.com/v4/letter/d/9dc877/32.png) [@drycloud](https://forum.arduino.cc/u/drycloud)\
**Post date:** [April 16, 2022, 7:00am UTC](https://forum.arduino.cc/t/dc-motors-run-when-powered-by-an-arduino-connected-to-a-computer-but-not-a-battery/981541/1 "2022-04-16T07:00:18Z")

</div>

The first image is when I can get the motors working by powering it through the Arduino when the Arduino is connected to my computer, and the second image is when the motors are powered by the battery. The motors turn so slowly it takes about 3 minutes to make a single full rotation, so I think it has to do with low voltage but not sure how to solve? It makes even less sense to me that the motors run fine on a 5V output from the Arduino but not a 9V battery.

Components:  
L298N Motor Controller  
Arduino UNO  
DAGU DG01 DC Motor

**Working when powered by Arduino**

 ![Untitled Sketch_bb3](https://europe1.discourse-cdn.com/arduino/original/4X/4/9/6/4964c5fd5af28b668ab5d00f5eb5ba3eb87f3115.png)

**Not working when powered by battery**

 ![Untitled Sketch_bb4](https://europe1.discourse-cdn.com/arduino/original/4X/6/e/d/6ed5a1c11127172ae1ec8a216ae3c88431ee2ae2.png)

**Code**

```cpp
int motor1pin1=2;
int motor1pin2=3;
int motor2pin1=4;
int motor2pin2=5;

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

void loop() {
  // put your main code here, to run repeatedly:
    digitalWrite(motor1pin1, HIGH);
    digitalWrite(motor1pin2, LOW);
    
    digitalWrite(motor2pin1, HIGH);
    digitalWrite(motor2pin2, LOW);  
}

```

---

<div class="post-metadata">

**Author:** ![anon35827816](https://avatars.discourse-cdn.com/v4/letter/a/ecae2f/32.png) [@anon35827816](https://forum.arduino.cc/u/anon35827816)\
**Post date:** [April 16, 2022, 7:06am UTC](https://forum.arduino.cc/t/dc-motors-run-when-powered-by-an-arduino-connected-to-a-computer-but-not-a-battery/981541/2 "2022-04-16T07:06:36Z")

</div>

> [@drycloud](#):
>
> a 9V battery

That's a very suitable battery for smoke alarms, but it's absolutely unfit for running motors. A 9V alkaline battery is good at providing a few microamperes for years on end, but simply will not source the kind of current (hundreds of milli-amperes or more) to run a motor.

---

<div class="post-metadata">

**Author:** ![drycloud](https://avatars.discourse-cdn.com/v4/letter/d/9dc877/32.png) [@drycloud](https://forum.arduino.cc/u/drycloud)\
**Post date:** [April 16, 2022, 7:11am UTC](https://forum.arduino.cc/t/dc-motors-run-when-powered-by-an-arduino-connected-to-a-computer-but-not-a-battery/981541/3 "2022-04-16T07:11:33Z")

</div>

I see but I've been following this tutorial using the same 9V battery, same DC motors, and wiring he appears to have but am not getting the same results.

[![](https://europe1.discourse-cdn.com/arduino/original/4X/4/2/8/428f998dfcd8cd4a4f38400e17d5fd95b115b59e.jpeg "How to use the L298N Motor Driver with Arduino - Quick Tutorial") ](https://www.youtube.com/watch?v=E2sTbpFsvXI)

---

<div class="post-metadata">

**Author:** ![anon35827816](https://avatars.discourse-cdn.com/v4/letter/a/ecae2f/32.png) [@anon35827816](https://forum.arduino.cc/u/anon35827816)\
**Post date:** [April 16, 2022, 7:15am UTC](https://forum.arduino.cc/t/dc-motors-run-when-powered-by-an-arduino-connected-to-a-computer-but-not-a-battery/981541/4 "2022-04-16T07:15:40Z")

</div>

So either you wired something wrong or there's a problem with your code. I can see neither, so perhaps it's a good idea to post a good photo of your setup and also post your code (using code tags please).

Still - don't use that 9V battery for this purpose. It's a waste, really, even if it (sort of) works.

---

<div class="post-metadata">

**Author:** ![drycloud](https://avatars.discourse-cdn.com/v4/letter/d/9dc877/32.png) [@drycloud](https://forum.arduino.cc/u/drycloud)\
**Post date:** [April 16, 2022, 7:21am UTC](https://forum.arduino.cc/t/dc-motors-run-when-powered-by-an-arduino-connected-to-a-computer-but-not-a-battery/981541/5 "2022-04-16T07:21:11Z")

</div>

Yeah I forgot to add the code but just added it. I will keep those tips in minds. I'm just learning so I'm willing to spare the batteries for now but what kind of battery or power source should be used instead?

---

<div class="post-metadata">

**Author:** ![anon35827816](https://avatars.discourse-cdn.com/v4/letter/a/ecae2f/32.png) [@anon35827816](https://forum.arduino.cc/u/anon35827816)\
**Post date:** [April 16, 2022, 7:23am UTC](https://forum.arduino.cc/t/dc-motors-run-when-powered-by-an-arduino-connected-to-a-computer-but-not-a-battery/981541/6 "2022-04-16T07:23:23Z")

</div>

I would suggest getting a bank of 3 to 4 rechargeable NiMH batteries for this kind of project - if it needs to be batteries. I personally always prefer to use a power supply that plugs into a wall socket. For example the well-known 'wall warts' that output 9V DC at 2A or so.

> [@drycloud](#):
>
> I'm willing to spare the batteries for now

Are you also willing to run into the situation where a project doesn't work as intended, you spend 3 days troubleshooting it only to find in the end that the battery really isn't suitable? You've been warned; I suggest you do something with this information.

---

<div class="post-metadata">

**Author:** ![drycloud](https://avatars.discourse-cdn.com/v4/letter/d/9dc877/32.png) [@drycloud](https://forum.arduino.cc/u/drycloud)\
**Post date:** [April 16, 2022, 7:28am UTC](https://forum.arduino.cc/t/dc-motors-run-when-powered-by-an-arduino-connected-to-a-computer-but-not-a-battery/981541/7 "2022-04-16T07:28:45Z")

</div>

I'll keep that in mind for more serious projects in the future.

---

<div class="post-metadata">

**Author:** ![anon35827816](https://avatars.discourse-cdn.com/v4/letter/a/ecae2f/32.png) [@anon35827816](https://forum.arduino.cc/u/anon35827816)\
**Post date:** [April 16, 2022, 7:33am UTC](https://forum.arduino.cc/t/dc-motors-run-when-powered-by-an-arduino-connected-to-a-computer-but-not-a-battery/981541/8 "2022-04-16T07:33:32Z")

</div>

Anything with motors, even small ones, does NOT go well with this kind of battery.

> [@drycloud](#):
>
> more serious projects

Electrons don't care if you're serious about a project.

Moreover, in this day and age, I find it very dubious if people insist on using batteries for projects like these, that wear down quickly and end up in a landfill. Such a shame.

---

<div class="post-metadata">

**Author:** ![drycloud](https://avatars.discourse-cdn.com/v4/letter/d/9dc877/32.png) [@drycloud](https://forum.arduino.cc/u/drycloud)\
**Post date:** [April 16, 2022, 8:12am UTC](https://forum.arduino.cc/t/dc-motors-run-when-powered-by-an-arduino-connected-to-a-computer-but-not-a-battery/981541/9 "2022-04-16T08:12:42Z")

</div>

It's my first project 😂 but fair point about batteries ending up in landfills. I'd love some rechargeable batteries and will look into getting some when I have the funds to do so. Thank you for all the advice.

---

<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:** [April 16, 2022, 8:46am UTC](https://forum.arduino.cc/t/dc-motors-run-when-powered-by-an-arduino-connected-to-a-computer-but-not-a-battery/981541/10 "2022-04-16T08:46:29Z")

</div>

Hi,  
Have you got this jumper installed?

 ![jumper](https://europe1.discourse-cdn.com/arduino/original/4X/d/5/a/d5aade58bc0b384ae9ae89f5964d60e21b1d7868.jpeg)  
It supplies the 5V terminal of the driver board with 5V from the boards 5V voltage regulator.

Tom.... 😃 👍 ☕ 🇦🇺

---

<div class="post-metadata">

**Author:** ![MarkT](https://avatars.discourse-cdn.com/v4/letter/m/c89c15/32.png) [@MarkT](https://forum.arduino.cc/u/MarkT)\
**Post date:** [April 16, 2022, 12:12pm UTC](https://forum.arduino.cc/t/dc-motors-run-when-powered-by-an-arduino-connected-to-a-computer-but-not-a-battery/981541/11 "2022-04-16T12:12:27Z")

</div>

BTW these days you can get "9V" batteries that are LiPo inside (and actually 7.4V), but these have good current handling and come with a USB charging connector.

Like this:  
[https://www.ebay.co.uk/itm/313945728186](https://www.ebay.co.uk/itm/313945728186)

---

<div class="post-metadata">

**Author:** ![anon35827816](https://avatars.discourse-cdn.com/v4/letter/a/ecae2f/32.png) [@anon35827816](https://forum.arduino.cc/u/anon35827816)\
**Post date:** [April 16, 2022, 3:55pm UTC](https://forum.arduino.cc/t/dc-motors-run-when-powered-by-an-arduino-connected-to-a-computer-but-not-a-battery/981541/12 "2022-04-16T15:55:49Z")

</div>

Yes, it might even be the case one of those was used in the video.

---

<div class="post-metadata">

**Author:** ![drycloud](https://avatars.discourse-cdn.com/v4/letter/d/9dc877/32.png) [@drycloud](https://forum.arduino.cc/u/drycloud)\
**Post date:** [April 16, 2022, 5:46pm UTC](https://forum.arduino.cc/t/dc-motors-run-when-powered-by-an-arduino-connected-to-a-computer-but-not-a-battery/981541/13 "2022-04-16T17:46:24Z")

</div>

Yes I do.

---

<div class="post-metadata">

**Author:** ![drycloud](https://avatars.discourse-cdn.com/v4/letter/d/9dc877/32.png) [@drycloud](https://forum.arduino.cc/u/drycloud)\
**Post date:** [April 16, 2022, 5:46pm UTC](https://forum.arduino.cc/t/dc-motors-run-when-powered-by-an-arduino-connected-to-a-computer-but-not-a-battery/981541/14 "2022-04-16T17:46:45Z")

</div>

Thank you for the referral.

---

<div class="post-metadata">

**Author:** ![drycloud](https://avatars.discourse-cdn.com/v4/letter/d/9dc877/32.png) [@drycloud](https://forum.arduino.cc/u/drycloud)\
**Post date:** [April 16, 2022, 7:28pm UTC](https://forum.arduino.cc/t/dc-motors-run-when-powered-by-an-arduino-connected-to-a-computer-but-not-a-battery/981541/15 "2022-04-16T19:28:14Z")

</div>

I have to say I think you are right that it is the battery. I'm looking at getting a NiMH power bank, something like this. [https://www.amazon.com/gp/product/B077Y9HNTF/ref=ppx\_yo\_dt\_b\_asin\_title\_o00\_s00?ie=UTF8&psc=1](https://www.amazon.com/gp/product/B077Y9HNTF/ref=ppx_yo_dt_b_asin_title_o00_s00?ie=UTF8&psc=1)

---

<div class="post-metadata">

**Author:** ![anon35827816](https://avatars.discourse-cdn.com/v4/letter/a/ecae2f/32.png) [@anon35827816](https://forum.arduino.cc/u/anon35827816)\
**Post date:** [April 16, 2022, 7:30pm UTC](https://forum.arduino.cc/t/dc-motors-run-when-powered-by-an-arduino-connected-to-a-computer-but-not-a-battery/981541/16 "2022-04-16T19:30:41Z")

</div>

That should do the trick alright!

---

<div class="post-metadata">

**Author:** ![Brazilino](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/brazilino/32/1198404_2.png) [@Brazilino](https://forum.arduino.cc/u/Brazilino)\
**Post date:** [April 16, 2022, 9:06pm UTC](https://forum.arduino.cc/t/dc-motors-run-when-powered-by-an-arduino-connected-to-a-computer-but-not-a-battery/981541/17 "2022-04-16T21:06:03Z")

</div>

Hi!

Thre´s another issue in your second setup.

When operating by battery, you can feed Arduino from the L298N 5V, **but not through the Vin pin**. This pin passes through the Arduino voltage regulator, which causes a voltage drop. The L298N already has a voltage regulator (the jumper mentioned above activates it). So you can connect it´s 5V directly to the +5V of the Arduino card.

Another option would be to connect the 9V battery to +12 of the L298N **and** to Arduino Vin, and leave L298N 5V with no connections.

In either case, @anon35827816 have a point, and the 9V battery shall be changed ASAP.

---

<div class="post-metadata">

**Author:** ![drycloud](https://avatars.discourse-cdn.com/v4/letter/d/9dc877/32.png) [@drycloud](https://forum.arduino.cc/u/drycloud)\
**Post date:** [April 16, 2022, 9:58pm UTC](https://forum.arduino.cc/t/dc-motors-run-when-powered-by-an-arduino-connected-to-a-computer-but-not-a-battery/981541/18 "2022-04-16T21:58:28Z")

</div>

That is very interesting about the voltage drop and about how the 5V port on the Arduino can work  
thank you for that. Yeah after fiddling around with it for a bit more and with @anon35827816 thoughts on the matter I too came to the conclusion it was the battery. And it will be nice to have a rechargeable battery adding less waste to the landfill while not having to worry about in the future if its a battery problem like he said.

---

<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 13, 2022, 9:58pm UTC](https://forum.arduino.cc/t/dc-motors-run-when-powered-by-an-arduino-connected-to-a-computer-but-not-a-battery/981541/19 "2022-10-13T21:58:51Z")

</div>

Closed on October 13, 2022, 9:58pm UTC

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