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

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

Not working when powered by battery

Code

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);  
}

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.

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.

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.

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?

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.

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.

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

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

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.

It's my first project :joy: 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.

1 Like

Hi,
Have you got this jumper installed?


It supplies the 5V terminal of the driver board with 5V from the boards 5V voltage regulator.

Tom.... :smiley: :+1: :coffee: :australia:

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

2 Likes

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

Yes I do.

Thank you for the referral.

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

That should do the trick alright!

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.

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.

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