:Problem with controlling 2 3V DC Motors with L298N

Hi! I am trying to power this set of wheels from an RC car that I bought, attached below. Each of the motors requires 3V.

I’m powering the Arduino and the L298N with a 9V battery and the connector, attached below.

I have a wire going from 5V on the L298N to 5V on the Arduino and ground to ground. I have pins IN3 and 4 on the L298N going to digital pins 7 and 8 on the Arduino and then ENB going to pin 9 for PWM.

I plugged the wires coming from the motors to OUT 3 and 4 and then plugged in the 9V battery to the Arduino to test for power and everything seemed to work fine.

I then uploaded this code:

void setup(){
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);

void loop(){
 digitalWrite(8, LOW);
 digitalWrite(7, HIGH);
 analogWrite(9, 100); 
 digitalWrite(8, HIGH);
 digitalWrite(7, LOW);

My motor makes a whining sound which I assume means that it isn’t receiving enough power or the rate that I set the PWM at is too high. I tried going down to 50 but that didn’t do anything.

I also tried to switch the wire going from 5V to 5V (L298N to Arduino) to 12V to Vin but that didn’t fix the problem either.

My motor makes a whining sound which I assume means that it isn't receiving enough power or the rate that I set the PWM at is too high. I tried going down to 50 but that didn't do anything.

Hmm, if you want to be giving more power you should be setting the number higher. Starting at 0 duty cycle to 100 percent duty cycle at analogWrite(PIN,255).

If it didn't move with analogWrite(9,100) it sure as beans won't move with analogWrite(9,50). Try a higher duty cycle.

The whine you are hearing is the PWM frequency (500hz). This frequency is the same regardless of the duty cycle, The fact that you hear the whine means the switching is working.

Those 9v square batteries are pretty well useless for powering motors. Make sure you have a power source that can handle the current.

Hi, Alka is right, I think.. you need analogWrite running up towards 255. And battery needs to be something like 6AA to the motor driver; L298N has quite a but of voltage drop.

An example HERE..

Thank you for the replies. I tried a few things but ultimately went back to the initial design that I had in my post but for whatever reason I don't get the whining noise from my motor anymore. I uploaded the code to the Arduino again and triple checked that the leads were all in the right spots but I can't figure out why the PWM doesn't do anything anymore. Any ideas?

Is 6 AA enough voltage? Is it a bad idea to buy an 8 AA battery pack?

It's not clear to me from your description, what voltage you have connected to the L298's Vs (pin 4 of the L298 multiwatt style), or where that voltage comes from. Seems you have the 5V logic connected (Vss on L298 pin 9) but I'm not sure about Vs which is the voltage to the motor (less the L298's inherent drop of 2 to 5V).

It's a cliche, but a picture really does replace 1000 words: can you post a circuit diagram?

This is what I have as a circuit. The battery is connected in the Arduino itself through a snap connector. The Vcc is the one on the L298N that supplies 5V. The DC motor is two 3V motors connected but they only have two leads, power and ground. I have attached the circuit diagram below.

You have no power supplied to the motor, Vs on L298. The 5V to the L298 is to run the chip, not the motor.


vs and vss.GIF

Ok, thank you. I don't have the chip I have the module. I'm not sure if that would make a difference. So in reference to the module, are you saying that the 5V output doesn't supply power to OUT 3 and 4, it just supplies power to the L298N itself?

That's the first time you mentioned a module.... from your first post you spoke of connecting to the L298 which to me meant the chip.

So in reference to the module

No idea.

Your image link doesn't work, rather attach it to the post, then edit later to use that image's address in a link.

Sorry I wasn’t clear enough. I have attached my image below.

I have no idea what the connections on that module do: what are the markings on that terminal block at the front? What’s the unused one on the left?

What do the manufacturer’s instructions say?

It’s possible that it only needs one power connection, if the module takes care of supplying both the logic and motor power from one input. Are there any on-board jumpers that dictate how that works?

In any case, even if that’s true, you won’t be supplying enough current from the Arduino 5V.

Here’s OP’s circuit diagram and photo



Have you read this tutorial?

Tom... :slight_smile:

Have you read this tutorial?

Well that puts a different slant on things: the right hand terminal on the module is a supply, providing power to the Arduino. (Leaving aside the wisdom of supplying the Arduino 5V on the wrong side of its regulator.)

And the left most pin is as I had suspected, the motor voltage supply. Presumably the module takes care of the 5V to the L298's logic.

Perhaps OP can proceed now?

I believe that I will be fine now. Thank you for the replies.