How to control 2 3vdc motor with L298 ?

Hi I'm a student here who has totally no knowledge about arduino, will definitely keep learning but can anyone guide me about the connections and program to run it?
So for Motor 1:

Output 1 & output 2 to motor
Input 1 & 2 & enable A to arduino.

Enable A has to be high for motor to work
If input 1 is high and 2 is low, motor will go one way.
If input 2 is high and 1 is low, motor will go other way.

for the second Motor:

Output 3 & output 4 to motor 2
Input 3 & 4 & enable B to arduino.

Enable B has to be high for motor to work
If input 3 is high and 4 is low, motor will go one way.
If input 4 is high and 3 is low, motor will go other way.
My connections are base on this link here:L298.jpg (image)
Anyone please guide me I have totally no directions .. would appreciate if there is help

I am not sure what your problem is.

From the title it looks like you are supplying too much voltage to your motor. You can cut this down using a resistor or by feeding the enable line to a PWM output and doing an analogue write to the pin to olny provide a limited duty cycle. For example if your motor would normally be getting 6V from the bridge then make it 50% with an analogWrite(pin,128);

For more info see:-

Hi there Mike Glad that I Could get your attention. Regarding the Connections i've made above, my program is like this
int d = 9;
int e = 10;
int f = 12;

void setup()
pinMode(d, OUTPUT);
pinMode(e, OUTPUT);
pinMode(f, OUTPUT);

void loop()
digitalWrite(f, HIGH);
digitalWrite(e, HIGH);
digitalWrite(d, LOW);

I'm only trying out 1 motor now. Any idea whats wrong with it ? Motor doesnt work. I notice my Arduino TX which is the transmitting light not lighting up too.

Two things:-

  1. When posting code on this forum please select the code and hit the # icon that formats it.
  2. What that code doesn't tell me is what you have connected to pins 9, 10 & 12

Are you loading the code into your arduino without any errors being reported?

Have you got the ground of your L298 to the arduino?
Are all the other pins wired like in the diagram you linked?
What motor voltage are you using?
Have you connected pin 9 to the arduino's 5V line?
Have you put the diodes on the motor like that setup shows? They are not very well drawn.

Best bet is if you get the data sheet for this device and give it a read, it has a typical circuit setup which you can match to what you have.

HI There Mike ! Sorry for the trouble.
I've connected the input 1(pin 5) to Arduino Duemilanove Pin 9(PM) and input 2(Pin 7) to Pin 10 of the arduino. And ENABLE A which is pin 6 of the L298n to the arduino Digital Pin 12.

regarding the questions:
I have both 3v and 9v motor, tried both, none could run.
Yes the pins are wired like the diagram
And i did connect Pin 9 which is the V Logic Supply to arduino 5V
Diodes? I'm not sure on how to put diodes inside :frowning:

What im confused now is whether my connections are wrong or my program is wrong. High doubt there is something wrong with my program as im sure the connection are like the Link stated.

When I said:-

What motor voltage are you using?

I was referring to the voltage on the motor supply pin of the L298. This has to be at least 2V higher than the logic supply voltage according to the data sheet. So if you are connecting that to 3V3 then it won't work.

Diodes? I'm not sure on how to put diodes inside

You don't put them inside anywhere you put them across the motor. They are shown (all be it drawn very badly) on that link you posted and go from each side of the motor to the positive supply and ground. They protect the circuit from the back voltage generated when the motors turn off.

Hi there !

I connected a 9V Battery to the motor supply pin and ground.

Just my doubt, is there anything wrong with my program ? are my connections of the input to the arduino right ?

Nothing wrong with the code because it dons't do anything but set pin levels. Can you post a photo of what you have made?

Hi there ! This is how it looks like .

The Yellow wires are the ENABLE A wire connected to digital pin 12 of arduino.
The White Wires are the inputs 1 and 2 connection to PWM pin 9 and 10.
The Green Wires are the motor Wires to Output 1 and 2 of the L298n.
The battery im using is a 9V Battery.

Your pins start from the wrong side.

Hi There BillHo !
Im Confused. Based on this link L298.jpg (image) There were 8long legs and 7 short legs. My L298N had 8 long legs and 7 short legged pins too.
The picture you showed me were the complete opposite, 8short legs and 7 Long legs.

Pin 1 will start from left side, short legs or Long legs will not matter.

Okay so I've reconnected it to the pin you showed me, and it looks like this. Its still not working :frowning: have been working for days to make it turn left and right with my program but still to no avail :frowning:

Is your pin 1 connected to Gnd?

Yes definitely Current sense A and GND are connected to Ground.

because in the photo it not connected Gnd on the same row. please check.

I did..
Connections are like this..
Pin 1 To Arduino GND, Pin 2 and Pin 3 to Motor, Pin 4 to My 9V battery holder Red Wire, Pin 5 to Arduino PWM pin9, Pin 6 To arduino Pin 12, Pin 7 to Arduino PWM pin10, Pin 8 to Arduino GND, Pin 9 to 5V or arduino. and lastly, the 9v battery holder black wire to L298N Pin 8.
Are there nothing wrong with the program ..?
Really sorry for the trouble

With respect, Arduinoobo, I think you still have your 'wires crossed'

I hope the attached drawing might help: I've drawn it looking from above, so the pins are down into the paper.


P.S. For simple motors, make sure (for each channel/motor) one input is High and the other Low. Switch 'em off with the enable pin.

P.P.S. If you e-mail me, I can send a printed-circuit board, etched, which you can populate


Hi there ! What's your email ?