Go Down

Topic: Interfacing L298N with Arduino Duemilanove (Read 11343 times) previous topic - next topic


Hello all,

I am working on a school project and am attempting to run a Linear Actuator (12V, max 3A draw) and small DC motor (12V, 150mA avg current and 600mA stall current) using an Arduino Duemilanove and L298N motor driver and controlled by a joystick with button switch (its actually the type of joystick used on those claw arcade games). Right now I'm just trying to get the motor to turn for 1 second upon pressing the button on the joystick, and will add the linear actuator later. However I can't get the motor to spin and have no idea what the problem is. Any advice would be greatly appreciated, thank you in advance. Also I have detailed pictures that clearly show my setup but I can't figure out how to add them to this post, so perhaps someone can tell me how to do that. In the mean time, I'll try and describe my wiring as best as possible...

On the Arduino:
-digital pin 2 is the input from the switch (the other side of the switch is connected to ground)
-digital pin 5 goes to IN1 on the L298N
-digital pin 8 goes to ENA on the L298N
-digital pin 10 goes to IN2 on the L298N
-Vin is connected to an external 12V battery
-Gnd is connected to neg side of battery
-5V goes to VLS on the L298N

(Also note that both Vin and VLS are connected to a 100nF capacitor which is connected to ground)

On the L298N (in addition to the previously mentioned connections from the Arduino) :
-OUT1 and OUT2 are connected to the two terminals of the motor
-Vs is connected to the 12V battery
-Gnd is connnected to neg side of battery

Finally heres the code I've written:

const int buttonPin = 2;     //RedButton switch pin
const int motorPin =  5;     //motor output pin
const int motorPin2 = 10;    //other motor pin
const int EnableMotor = 8;   //Enables H-Bridge for Motor

void setup()
           // initialize the input and output pins from switch and to L298:

 pinMode(buttonPin, INPUT);
 digitalWrite(buttonPin, HIGH);  
 pinMode(motorPin, OUTPUT);  
 pinMode(motorPin2, OUTPUT);
 pinMode(EnableMotor, OUTPUT);  

 digitalWrite(EnableMotor, HIGH);  //enable IN1 on L298N

void loop(){

 if ((digitalRead(buttonPin) == HIGH))
   // turn motor on:
   digitalWrite(motorPin, HIGH);
   digitalWrite(motorPin2, LOW);
   delay(1000);                //rotate motor for 1 sec
   digitalWrite(motorPin, LOW);
   delay(2000);                //Pause for 2 sec to disallow rapidfire
   // turn motor off:
   digitalWrite(motorPin, LOW);


Look at the pinout on data sheet (the L298 and SN754410 are pin compatible): http://www.pololu.com/file/0J65/sn754410.pdf

Notice the symetry due to its being 4 half bridges. Check your circuit that 4,5,12,13 go to ground and 8,16 go to Vcc. Use black wires for ground and red wires for Vcc. The colors make many errors obvious.

Next focus on the first h-bridge, pins 1, 2, and 3. Connect 1 and 2 to high and measure the output of pin 3 with a volt meter. Leave pin 1 high and change pin 2 to 0v. Check that pin 3 is now 0v.

You have now mastered the h-bridge. Optionally, PWM can be used to control power over pins 1 and 9.

Now connect pins 1 and 2 to your arduino, run your sketch and measure the output with a voltmeter. Once this works, connect your motor.

If you don't have a voltmeter use an led and resistor. Of course this only works when the output is positive, i.e. backwards won't light the led.

It sounds from your below description that you might not have set all the pins on the L298N.

Good luck!


Nov 05, 2010, 10:10 pm Last Edit: Nov 05, 2010, 10:15 pm by 3dprinter Reason: 1
This link has helped me a lot ...

Please not the diodes, they are important as they will stop the back EMF of the motor coils damage your chip.


Thank you all for your quick responses,

Richard, thank you for alerting me to the fact that I need to connect CSA to GND, unfortunately that alone did not solve the problem.

Andy, I checked out the link you provided but am not able to understand which pins correspond to 4, 5, 12, and 13 that need to go to ground. Currently I have GND and CSA going to ground from the L298N, and since I am not yet using the second H-Bridge I have not connected CSB to ground, should I be connecting those anyway? But still I do not see which the 4th pin to ground should be.

Here are some links to my wiring diagram and also some photos I have taken of all my components. Thank you all again for your support, it means a great deal to me.

Wiring Diagram: http://img255.imageshack.us/img255/5363/wiringdiagram.jpg

Entire Setup: http://img255.imageshack.us/img255/4117/fullpic.jpg

Arduino: http://img248.imageshack.us/img248/9836/arduino.jpg

L298N: http://img255.imageshack.us/img255/8760/l298n.jpg
This picture does not show CSA being connected but I have since connected it to ground.

Breadboard: http://img255.imageshack.us/img255/3985/breadboard.jpg
The capacitor on the left connects the input from the 12V battery to Vin on the Arduino and VS the L298N, and the capacitor on the right connects 5 V from the arduino to VLS on the L298N. The opposing side of both capacitors are connected to ground.


I had the wrong diagram referenced, but I see you have the right one now. The same comments still hold: First get the h-bridge to work without the Arduino or motor. Apply fixed voltages to bridge inputs and measure the output with a voltmeter. Then connect it to the motors and see if you can make it spin. When you test in this way its much easier to understand what is going on and troubleshoot.



I apologize, I was a bit careless when I drew that last schematic. I had it wired according to the updated diagram below, but just failed to draw it correctly...(thats what happens when you try to work on too much caffeine and not enough sleep!!). Here is what my wiring diagram actually looks like.


CSA was indeed connected to ground...I had mislabled it ENA. ENA was actually connected to +5V from the arduino. VS was connected to the + side of my battery. Finally the Arduino and L298N GND's were both connected to the - side of the battery.

Anyway, I tried removing the switch and using the Arduino only for the 5V supply to power the VLS, ENA and IN1 pins, but was still not able to get the motor spinning. Using a multimeter I found that I was getting a 12V drop across VS, and a 5V drop on pins ENA, IN1, and VLS, and had IN2, CSA, and GND all grounded. However there is no voltage across OUT1 and OUT2. Any ideas what I'm doing wrong, or is it possible that the chip is a dud and I should just buy a new one? Here is the schematic I used for testing purposes:


Thank you all again for your help, I greatly appreciate the support I am receiving.


I just now tried connecting to the B side and found similar results, except I realized that I was not getting the 5V drop I expected on the ENB pin. The other side of the wire connected to the breadboard is at 5V, but the side connected to the L298N is at 0. How is it possible that the ENB pin on the IC is different than the other side of the wire?

I next switched everything back to the setup for the A side according to my previous "testing schematic" and similarly found that there ENA was not receiving 5V even though the other side of its wire was at 5V. Any ideas whats going on here?


I couldn't feel the wire heating up and it certainly wasn't melting. Also I used different wire when I tested the B side and the A side, yet the same problem was occurring for ENB and ENA where one side was at 5V and the other side at 0. It seems unlikely that I picked two wires that are duds...any other possibilities? I am expecting my new L298N's to arrive today or tomorrow at the latest, so I'm anxious to find out if the exact same wiring setup will get me results with fresh IC's.

Thanks again for your help, I feel like I'm learning so much from this forum in such a short period of time.


Haha, you are probably right but its still a mystery at this point what the problem is. I measured it on the bottom of the protoboard on the solder lead, which is the only part of the wire that is exposed. Measuring all the other pins on their respective soldered joints worked, so I am really confused as to whats going on here.



Alright I can finally report some progress! I received a new L298N yesterday, and by wiring it up according to the testing schematic, I was able to get the motor to finally spin. However when I tried uploading the sketch onto the arduino so I could add the switch, I got the following error:

avrdude: stk500_getsync(): not in sync: resp=0x00
avrdude: stk500_disable(): protocol error, expect=0x14, resp=0x51

I was able to upload sketches successfully before today so I'm not sure whats going on here. Does anyone know what that error message means?


Nov 13, 2010, 05:12 am Last Edit: Nov 13, 2010, 05:13 am by ZXElite065 Reason: 1
YAY!!! I tried it with a new Arduino and it works, my motor is finally working!

Still have no idea whats wrong with the old one though... I googled the error and found several posts on this forum and others regarding the same issue. I made sure it was connected to the correct COM port, changed the baud from 9600 to 57600, restarted the computer...all without result. I noticed that when uploading the yellow L light is not blinking and neither are the TX or RX lights, except maybe once or twice dimly. I'm thinking of just sending it back and exchanging it for a new one. Anything else I could try before doing that?



I'm thinking of just sending it back and exchanging it for a new one. Anything else I could try before doing that?

You destroyed it through carelessness/cluelessness, and you think the seller should warranty it?

You could try admitting that it was your fault that you toasted it.
The art of getting good answers lies in asking good questions.


Take the old chip and put it into the new circuit replacing the new chip, and see if the old chip works works. I doubt that where you purchased the chip will take the old one back. The is a general rule with electronic parts is no returns.
Google forum search: Use Google Search box in upper right side of this page.
Why I like my 2005 Rio Yellow Honda S2000  https://www.youtube.com/watch?v=pWjMvrkUqX0


Although I cannot upload new programs to the Arduino, everything works fine when I connect it to an external supply...it still runs my motor fine when I press my switch, so I'm not convinced the arduino is fried altogether.

I will be quick to admit that I am not an expert with electronics, and no doubt it was something I did that is causing the problem. I'm still in the learning process which is why I'm using this forum to get help. I'm trying to figure out what exactly it was that I could have done so that I don't repeat my mistakes. I am now getting the same issue with the second Arduino that I bought. I was able to upload a program initially, then run the system from an external power supply. However when I plug it back into my computer and try to upload a new program, I get the sync error. Any constructive comments would help, thank you.

Go Up