Introduction: Arduino Modules - L298N Dual H-Bridge Motor Controller

Picture of Arduino Modules - L298N Dual H-Bridge Motor Controller

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:

Picture of Getting to Know Your L298N Dual H-Bridge Motor Controller Module:


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.


  • 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)


  • 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:

Picture of 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.


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


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

Download the attached L298N_Dual_H_Bridge_Keyboard_Control_Reichenstein7.ino

Alternate Download:


Reichenstein7 (author)2014-12-29

I have added a link to the .ino file via Mediafire for those who are still seeing formatting errors.

YveG1 (author)Reichenstein72015-07-12

Why do you connect Pi's 5V to the 5V on the board??

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???!

Reichenstein7 (author)YveG12015-08-28

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.

IgorS32 (author)Reichenstein72015-12-06

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.

flocsy (author)2017-11-25


I tried this with both of the modules you have in the instructions (one with the blue connectors for the motor on the opposite side, and the other with the yellow motor connectors on the same side). I am trying to control using PWM, so I use this:

// it's value is calculated in another function, where I read a rotary encoder.

// The value is [0-100] with steps of 10

int pwmSpeed;

void setPWM() {

digitalWrite(LOCO_LEFT_PIN, direction == 1 ? HIGH : LOW);

digitalWrite(LOCO_RIGHT_PIN, direction == -1 ? HIGH : LOW);

analogWrite(LOCO_SPEED_PWM_PIN, pwmSpeed);


When I test the code "dry" it all looks good. I turn the rotary encoder 1 click to either side and the values of direction and pwmSpeed are printed out and are correct.

However when I put a loco (model train) on the rails, then whenever I output anything but 0 to the pwm pin, then I just hear a buzz sound from the loco's engine. Any idea why?

flocsy (author)flocsy2017-12-01

it turned out that it works, it's just the nature of low frequency PWM. On higher duty cycles the motor starts to spin. On higher frequency you don't hear the buzz.

Champarl (author)2017-02-28

According to the L298n'datasheet, their is current sensors on this chip. We can see the output on the "wiring picture" (CSA and CSB pins).
I bought this chip but in the configuration of your first picture .
Any ideas to have an acces to current sensor ?

flocsy (author)Champarl2017-12-01

did you figure out how to use CSA,CSB with arduino?

MuhannadS2 (author)2017-11-24

I already know the way of change the speed of motors, but i wonder how the H-Bridge control the speed ?

Packers_Fan (author)2017-04-03

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?

VedA1 (author)Packers_Fan2017-11-06

Yes. You could. One driver can control two motors. First parallel both outputs for double current. If that is not enough connect more drivers and parallel all outputs

Stephen RoyK (author)2017-08-30

Can i use it as 5v power source after connecting 12v supply

fbujold (author)2016-07-30

I have been searching for a while but i cannot find the answer.

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 "one turn" (200 pulse) stepper sample routine. Runs like a charm for about 90 seconds then thermal protection kicks in??

Any idea anyone?

tengfoong_lam (author)fbujold2017-07-24

I got the same problem supplying 12V to power my stepper motor. Apparently the battery was supplying too much power to the driver and after awhile, the steppers will stall, probably due to the chip overheating. Essentially, the solution is to use the EnA and EnB pins to control the power going to the stepper.

What I did was:

1) I kept the 12V Jumper ( Labelled number 3 in on the chip, contrary to instructions online that indicated that is should be removed if supplying >12V. I tried removing it and the entire chip would not function at all.

2) I took out the jumpers from PWM pins EnA and EnB. I connected two Arduino Pins with PWM functionality (Eg 45 and 46 on the Arduino Mega) to EnA and EnB. In the Arduino Code, I used analogWrite for the pins and adjusted the written value (should be around 50-200 depending on power source and stepper motor specs) until the power supplied to the stepper is just right so it can rotate over a long time without the driver overheating).

Note 1: Maximum value for analogWrite is 255, which is equivalent to attaching the jumpers back onto EnA and EnB pins, which means full power from the battery is being supplied to the stepper. So a value lower would reduce power to the stepper and prevent overheating.

Note 2: I use "power" in my answer because I am not sure whether the voltage or current is at fault here. Maybe an electronics expert could shed some light on this?

Yeap that's the answer I came up with based on my experimentation with this motor driver. Most tutorials on the internet disregard the En pins when teaching how to wire up stepper motors, which is a solution that will only work if your battery source is tailored to the stepper motor you are using.

fbujold (author)fbujold2016-07-30

Forgot, i am running the bridge from 7 to 9 VDC, with the same results

mrfloid (author)fbujold2016-09-07

Maybe 2A or 25W were exceeded?

Or maybe power regulator isn't working fine, so you could take off the 5V jumper and supply external 5V por logic operation

ElmoO2 (author)fbujold2016-08-29

I'd suggest a stepper driver.

AIP06 (author)2017-07-05

do you know how to replace the l298n with other comonents

dsyafiq (author)2017-05-20

why i cannot use after download

Mihai Bucur made it! (author)2017-03-20

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

Here are some pics :D


LouisDT (author)2017-01-25

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?

TumP2 (author)LouisDT2017-02-23

i know your problem , i can solve complete

LouisDT (author)TumP22017-02-24


TumP2 (author)LouisDT2017-02-24

you need use opto isolator for separate ground .

kuldeep_v (author)2017-02-16

Hi ,can I use this to drive a bipolar stepper motor upto 3 to 4A and 24 volts .


AnshulBansal (author)2017-01-30

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?

trymore (author)2016-05-25

can the dual H BRIDGE LN298N drive a 24v 6 A full load motor at 12v

T_dawgr (author)trymore2017-01-20

no man it can give maximum 2 amps...

giannisp5 (author)2016-04-07

Can I bridge the 2 Outputs of the driver to control 1 DC motor 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?

Antoine L (author)giannisp52017-01-18

Hello Giannis, i would like to do the same thing, did you have any luck with that? Did you try it out?


jpuno (author)2017-01-17

why is it , when I put a 12v supply the output voltage is around 5v?

ravitptc (author)2016-11-04

​How can i controll 2 DC motors? I am using Raspberry Pi Model 3-B and an L298N driver circuit?

SvenH23 (author)ravitptc2017-01-11

the h Bridge will Do.if you use python, Tiere are some good explanations to find at YouTube.



OIY555 (author)2016-12-21


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)

I've tried with half speed and full speed, nothing moves.


trymore (author)2016-05-25

can i drive a 24V dc 6Afull load motor using the H BRIDGE L298N

cknox6 (author)trymore2016-08-22

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.

However, given the voltage and current ratings of your motor, I'd invest in something a little more heavy duty than this.

jkwilborn (author)cknox62016-12-19

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 ^-^ ...

IgorS32 pointed this out to everybody in his note about the bad practice of tying different power supply outputs together. Same game...

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.

Half (or more) of these questions would not be asked if they would use the thing their hands are on. I googled "l298n current limit", scrolled down and found the following entry

"Motor driver: L298N. Motor channels: 2. Maximum operating voltage: 46 V. Peak output current per channel: 2 A. Minimum logic voltage: 4.5 V. Maximum logic ..."

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.

Probably found their way here with a search engine anyway. Putting the load on people like Reichenstein7, who did such a great article!... ;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.


The dumbest person can ask the smartest man questions he cannot answer.

P.S. Sorry it was so long...

Moezzzz (author)trymore2016-06-10

no you can not because the maximum current of a bridge is 2A max. for more information see the L298 datasheet

siddhantchoyal (author)2016-08-01

Thnx a lot ... u got me outta a big trouble :)

larystoy (author)2016-07-11

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.

Taceey (author)2016-07-08

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?

slokaz (author)2016-06-19

so if I want to use a simple brushed DC motor, would I connect the two wires from the motor to OUT1 and OUT2?

superenigma (author)slokaz2016-06-24

Yes, that's what you would do

MohammedI40 (author)2016-05-23

hy all

ableinstructor (author)2016-05-19

Is the L298N compatible with brushless or brushed motors? Do I need to add an ESC to run brushless motors? Thanks!

Nama'aS (author)2016-05-04

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 ?

asingh8 (author)2016-04-13

Hey Reichenstein7, can we replace L298N with Sabertooth 2x25 to drive heavy motors, without changing any other connections?

Sakib Ahmed (author)asingh82016-04-22

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.

Shubham PatiT (author)2016-03-11

Can 1 L298N be used to control 2 stepper motors???

Pedro1291 (author)Shubham PatiT2016-03-28


About This Instructable




More by Reichenstein7:Boneless Pork Loin With Bacon LatticeUArm Miniature Palletizing Robot Arm for ArduinoGeneral Tso Boneless Ribs
Add instructable to: