loading

Quick and simple start guide for using and exploring an L298N Dual H-Bridge Motor Controller module with an Arduino.

The model in the example I am using is from Ebay.

Materials needed:

  • L298N Dual H-Bridge Motor Controller module (various models will work)
  • Male to Female jumper wires
  • An Arduino, any flavor.
  • A DC power supply, 7-35v
  • A motor that is the correct voltage for your power supply used.

Step 1: Getting to Know Your L298N Dual H-Bridge Motor Controller Module:

Usage:

H-Bridge's are typically used in controlling motors speed and direction, but can be used for other projects such as driving the brightness of certain lighting projects such as high powered LED arrays.

How it works:

An H-Bridge is a circuit that can drive a current in either polarity and be controlled by *Pulse Width Modulation (PWM).

* Pulse Width Modulation is a means in controlling the duration of an electronic pulse. In motors try to imagine the brush as a water wheel and electrons as a the flowing droplets of water. The voltage would be the water flowing over the wheel at a constant rate, the more water flowing the higher the voltage. Motors are rated at certain voltages and can be damaged if the voltage is applied to heavily or if it is dropped quickly to slow the motor down. Thus PWM. Take the water wheel analogy and think of the water hitting it in pulses but at a constant flow. The longer the pulses the faster the wheel will turn, the shorter the pulses, the slower the water wheel will turn. Motors will last much longer and be more reliable if controlled through PWM.

Pins:

  • Out 1: Motor A lead out
  • Out 2: Motor A lead out
  • Out 3: Motor B lead out
  • Out 4: Mo (Can actually be from 5v-35v, just marked as 12v)
  • GND: Ground
  • 5v: 5v input (unnecessary if your power source is 7v-35v, if the power source is 7v-35v then it can act as a 5v out)
  • EnA: Enables PWM signal for Motor A (Please see the "Arduino Sketch Considerations" section)
  • In1: Enable Motor A
  • In2: Enable Motor A
  • In3: Enable Motor B
  • In4: Enable Motor B
  • EnB: Enables PWM signal for Motor B (Please see the "Arduino Sketch Considerations" section)

Specifications:

  • Double H bridge Drive Chip: L298N
  • Logical voltage: 5V Drive voltage: 5V-35V
  • Logical current: 0-36mA Drive current: 2A (MAX single bridge)
  • Max power: 25W
  • Dimensions: 43 x 43 x 26mm
  • Weight: 26g

*Built-in 5v power supply, when the driving voltage is 7v-35v

Step 2: Wiring to an Arduino:

There are several different models of these L298N Dual H-Bridge Motor Controllers. The generic wiring schematic above should do the trick for most.

Two things to mention;

  • Make sure you have all of your grounds tied together; Arduino, Power source, and the Motor controller.
  • The PWM Pins are unnecessary if you do not want to control PWM features.

Step 3: Arduino Sketch Considerations:

The Arduino code sketch is pretty straight forward. Since there isn’t a library for the L298N Dual H-Bridge Motor Controller you just have to declare which pins the controller is hooked to.

The “int dir(number)Pin(letter)”‘ pins can be connected to any available digital pin you have available, as long as you declare the correct pin in your sketch. This makes the L298N Dual H-Bridge Motor Controller very versatile if your project is using a lot of Arduino pins.

The int“speedPin(letter)” pins need to be connected to a PWM pin on the Arduino if you want to enable speed control through PWM.

As a quick cheat I have included a list of PWM pins for the main two types of Arduino's I use:

  • AT MEGA – PWM: 2 to 13 and 44 to 46. Provide 8-bit PWM output with the analogWrite() function.
  • UNO – PWM: 3, 5, 6, 9, 10, and 11. Provide 8-bit PWM output with the analogWrite() function.

Step 4: Arduino Sketch Example:

This code example I wrote to allow a serial monitor program such as Putty to control the L298N Dual H-Bridge Motor Controller via a keyboard with key presses.

Controls:

Key .......... Motor

1 ............... Motor 1 Forward

2 ............... Motor 1 Stop

3 ............... Motor 1 Reverse

4 ............... Motor 2 Forward

5 ............... Motor 2 Stop

6 ............... Motor 2 Reverse

Code:

  • Fixed the formatting issues (12/29/2014):

Download the attached L298N_Dual_H_Bridge_Keyboard_Control_Reichenstein7.ino

Alternate Download: http://www.mediafire.com/download/z654e8at1b21d7e/L298N_Dual_H_Bridge_Keyboard_Control_Reichenstein7.ino

<p>I have added a link to the .ino file via Mediafire for those who are still seeing formatting errors.</p>
<p>Why do you connect Pi's 5V to the 5V on the board??</p><p>This seems weird. Everywhere else I read that the board will supply 5V when running off 7-12V supply. But they never say you should put 5V from the Pi in it???!</p>
<p>This step is not necessary, I like to tie together rails of equal v-value for stability of my projects (some components are heavier draw than others and v-droop is annoying). What is necessary is to make sure your projects components are always grounded together.</p>
<p>That's not a good idea. In the best case it won't do a thing, in the worst (most likely) case, you are shorting 2 voltage sources that are *not* identical, hence generating a voltage delta across a very small resistor.</p>
<p>why i cannot use after download</p>
<p>Is it possible to double up on the controllers for a moor that has a higher current draw than what is rated for this device?</p>
<p>Hello, i have the same motor driver, and i am trying to make an obstacle avoiding car. I am using scrap parts from old rc cars.The dc motors are being powered with 4X 1.5v batteries, trgough the driver, but the left motor gets 2.4 v and the right motor gets only 0.5 v , do you know what trhe problem would be? If i lift the car from the ground the motors starts to spin , but when is on the ground they will not move, so they cannot push the car, do you know where it is the problem, van you help me? :D</p><p>Here are some pics :D</p><p>Thanks!</p>
Hello,<br>According to the L298n'datasheet, their is current sensors on this chip. We can see the output on the &quot;wiring picture&quot; (CSA and CSB pins). <br>I bought this chip but in the configuration of your first picture . <br>Any ideas to have an acces to current sensor ?
<p>I have a problem. When i power up the L298N with a 9V batteri, and i try to power up a little dc motor (6-9V), then the amount of output voltages falls over the first couple of seconds until there is no output voltage at all. I do not know what i am doing wrong. Can anyone please help?</p>
<p>i know your problem , i can solve complete</p>
<p>HOW?</p>
<p>you need use opto isolator for separate ground .</p>
<p>Hi ,can I use this to drive a bipolar stepper motor upto 3 to 4A and 24 volts .</p><p>Thnaks</p>
<p>Can I power 2 dc motors as well as 2 servos with the 5v output if I am using a 7.4v battery? I want to use this for a robot car. Hence, all the motors will not be working at the same time. Can I do this?</p>
<p>can the dual H BRIDGE LN298N drive a 24v 6 A full load motor at 12v</p>
<p>no man it can give maximum 2 amps...</p>
<p>Can I <u>bridge the 2 Outputs of the driver to control 1 DC motor</u> that needs 4A? If possible, will the driver think that it has 2 motors and if so, do I have to send (HIGH, LOW) commands to all 4 pins in order to do this? </p>
<p>Hello Giannis, i would like to do the same thing, did you have any luck with that? Did you try it out? <br><br>Antonis</p>
why is it , when I put a 12v supply the output voltage is around 5v?
​How can i controll 2 DC motors? I am using Raspberry Pi Model 3-B and an L298N driver circuit?
<p>the h Bridge will Do.if you use python, Tiere are some good explanations to find at YouTube.</p><p>Regards</p><p>Sven</p>
<p>Hi,</p><p>What can be the reason that when using the PWM, the motors do not work at all? (While when the jumper is in place they do move back and forth according to the program in loop)</p><p>I've tried with half speed and full speed, nothing moves. </p><p>Thanks!</p>
<p>can i drive a 24V dc 6Afull load motor using the H BRIDGE L298N </p>
<p>If you look at the L298N datasheet, it is possible to hook up the two H bridges in parallel to pull a 4A load, which for your case might be enough. <br><br>However, given the voltage and current ratings of your motor, I'd invest in something a little more heavy duty than this.</p>
<p>I saw no indication that you could hook these up in parallel in the data sheet, if so, please point that out to me. Most things like this you can't parallel because the small differences in voltage when they switch is a problem. When you do attempt this, at minimum you need some kind of resistance to allow the load to balance. That is usually what you don't want to do as you want it to switch with the lowest on resistance. So adding resistance is futile ^-^ ...</p><p>IgorS32 pointed this out to everybody in his note about the bad practice of tying different power supply outputs together. Same game...</p><p>It indicated (to me, the datasheet) that you can pull 4 amps through one side or the other (only one motor port can be used.) Or something like 3.25 amps on one motor and 750 milliamps on the other, adding up to 4 amps total. This makes sense since the heat dissipation (heat sink) is probably connected to both controllers and if one is unused it will change the others thermal characteristics, as far as how much heat (amps) it can tolerate.</p><p>Half (or more) of these questions would not be asked if they would use the thing their hands are on. I googled &quot;l298n current limit&quot;, scrolled down and found the following entry</p><p>&quot;Motor driver: <em>L298N</em>. Motor channels: 2. Maximum operating voltage: 46 V. <em><strong>Peak output <em>current</em> per channel: 2 A</strong>.</em> Minimum logic voltage: 4.5 V. Maximum logic ...&quot; </p><p>Took me less than 30 seconds... This is not demeaning but it is stress the education of the possibilities of these search engines and their incredible caches of data. It is only to help them learn what a great tool it is and how under. used. it is.</p><p>Probably found their way here with a search engine anyway. Putting the load on people like Reichenstein7, who did such a great article!... ;p}</p><p>If you require 50% more than the devices' limit (not only in amps, but anything else), forget that part and move on. By this description it's 300% more power than possible with this device.</p><p>IMHO :-O</p><p>The dumbest person can ask the smartest man questions he cannot answer.</p><p>P.S. Sorry it was so long...</p>
<p>no you can not because the maximum current of a bridge is 2A max. for more information see the L298 datasheet</p>
<p>I have been searching for a while but i cannot find the answer.</p><p> I connected a stepper motor to A and B output, left the 5 volt and both enables jumper in place, connected the IN1-4 to arduino 8-11, feed the arduino with the bridge 5 V source, loaded the arduino &quot;one turn&quot; (200 pulse) stepper sample routine. Runs like a charm for about 90 seconds then thermal protection kicks in??</p><p>Any idea anyone?</p>
<p>Forgot, i am running the bridge from 7 to 9 VDC, with the same results</p>
<p>Maybe 2A or 25W were exceeded? </p><p>Or maybe power regulator isn't working fine, so you could take off the 5V jumper and supply external 5V por logic operation</p><p><a href="http://blog.pennybuying.com/down/f/F815A.pdf" rel="nofollow">http://blog.pennybuying.com/down/f/F815A.pdf</a></p>
<p>I'd suggest a stepper driver.</p>
<p>Thnx a lot ... u got me outta a big trouble :)</p>
<p>On the H-bridges I am using I used super glue to attach a 40 mm X 10 mm 12v fan to each controller, no overheating issues with them yet.</p>
<p>Might be late to the party, but i cant seem to get my l298n to drive 2 motors at the same time. Anyone got any blue what im doing wrong?</p>
<p>so if I want to use a simple brushed DC motor, would I connect the two wires from the motor to OUT1 and OUT2?</p>
<p>Yes, that's what you would do</p>
hy all
<p>Is the L298N compatible with brushless or brushed motors? Do I need to add an ESC to run brushless motors? Thanks!</p>
<p>Hello Reichenstein7, there is something I don't quite understand. If I wanted to control the motor's position, and I have a motor that has positional feedback. Should the two digital outputs from the Arduino be connected to In1 and In2 or ENA ?</p>
<p>Hey Reichenstein7, can we replace L298N with Sabertooth 2x25 to drive heavy motors, without changing any other connections?</p>
<p>In short, no. But with little adjustments, yes. Cuz, Sabertooth 2x25 works in a different way and takes input differently. Read the data sheet and you will see why.</p>
<p>Can 1 L298N be used to control 2 stepper motors???</p>
<p>no</p>
<p>Found sumthng new reated to the same.</p><p><a href="http://vaaiibhav.me/how-to-drive-a-stepper-motor-using-arduino-and-l298h-bridge/" rel="nofollow">http://vaaiibhav.me/how-to-drive-a-stepper-motor-u...</a></p>
<p>Hello has anybody created the L298 Dual H-Bridge Motor Driver in Fritzing? I want to implement into one of my projects. Please share!</p>
<p>can this L298N Dual H-Bridge be used with R/C ?</p>
<p>Found sumthng new reated to the same.</p><p><a href="http://vaaiibhav.me/how-to-drive-a-stepper-motor-using-arduino-and-l298h-bridge/" rel="nofollow">http://vaaiibhav.me/how-to-drive-a-stepper-motor-u...</a></p>
Can i get this module with a 5 A current?
<p>why does it need 4 pwm pins every motor should use only 1 pwm pin</p>
<p>For every motor you need 1 PWM output and 2 digital outputs (see fig. 6 in </p><p>http://www.st.com/web/en/resource/technical/document/datasheet/CD00000240.pdf)</p>
<p>I just got my controller working! It's exactly the same model as the one in this tutorial, which was very helpful! But there's a trick to this model, just something I noticed. Instead of declaring a PWM speed control pin, I just left the jumpers on ENA and ENB on, because they automatically enable the Motor A and B. Then I just PWM'ed either IN pins on the controller. I found that I could still vary the speed of the motor this way, even with one less connection. Is this the correct way to go? I want to make sure that even if the motor seems to work, I'm not damaging anything or wasting a lot of energy in the process. Because I have noticed that the heat sink gets extremely hot. (I'm inputting around 14-16V).</p>

About This Instructable

653,143views

295favorites

License:

More by Reichenstein7:Boneless Pork Loin With Bacon Lattice UArm Miniature Palletizing Robot Arm for Arduino General Tso Boneless Ribs 
Add instructable to: