← Components

Component

L298N motor driver with Arduino: pinout, wiring and code

The L298N is a dual H-bridge motor driver. It lets an Arduino set the speed and direction of two DC motors, or four wired in pairs, from their own battery. Wire ENA and ENB to PWM pins and IN1–IN4 to any digital pins, join the two boards’ grounds, and pull the ENA/ENB jumper caps off.

The Arduino decides. The L298N does the pushing. It is the one part in this car that can be destroyed by a wiring mistake, and the one whose behaviour most often gets blamed on the code.

L298N pinout

The module has three groups of connections: a screw terminal for power, two screw terminals for the motors, and a row of header pins for the Arduino.

L298N motor driver module pinout: motor A on OUT1 and OUT2, motor B on OUT3 and OUT4, power in on +12V, GND and +5V, and the ENA, IN1 to IN4, ENB header to the Arduino
The real module, and what each side connects to. The drawing below labels every pin.
L298N pinout: OUT1 and OUT2 on the left for motor A, OUT3 and OUT4 on the right for motor B, +12V, GND and +5V power terminal at the bottom left, and the ENA, IN1, IN2, IN3, IN4, ENB control header at the bottom right.L298NOUT1OUT2MOTOR AOUT4OUT3MOTOR B+12VGND+5VPOWERENAIN1IN2IN3IN4ENBTO ARDUINO
The L298N module from above. Coral: the ENA/ENB caps; remove them for speed control. Grey: the 5V-enable jumper; leave it on.
PinGroupWhat it does
+12Vpowermotor supply in, 5–35V despite the label
GNDpowerground; must also connect to the Arduino’s GND
+5Vpower5V out from the onboard regulator while the 5V-enable jumper is on
OUT1, OUT2motor Aone motor, or one side of the car
OUT3, OUT4motor Bthe other motor or side
ENAcontrolspeed of motor A, from a PWM pin
IN1, IN2controldirection of motor A
IN3, IN4controldirection of motor B
ENBcontrolspeed of motor B, from a PWM pin

Two channels, A and B. This car wires the two left motors in parallel to one channel and the two right motors to the other, which is how one L298N drives four wheels.

Four gear motors on one L298N: the two left motors wired in parallel to OUT1 and OUT2, the two right motors in parallel to OUT3 and OUT4.FRONT LEFTREAR LEFTFRONT RIGHTREAR RIGHTOUT1 · OUT2OUT3 · OUT4
Each side’s two motors share one channel, wired in parallel, so they always turn together. If a side runs backwards, swap its two wires at the terminal.

Why an Arduino needs a motor driver

An Arduino pin can signal, but it cannot push. A pin supplies roughly 20 milliamps. One of the gear motors in this build wants a few hundred. Wire a motor straight to a pin and you do not get a slow car — you get a dead Arduino.

So the driver sits in between. The battery feeds it directly, and the Arduino only tells it which way and how hard, over six thin signal wires carrying almost no current at all.

How it works, in one paragraph

Inside each half of the board is an H-bridge: four switches arranged in a square with the motor across the middle. Close the top-left and bottom-right pair and current runs through the motor one way. Close the other diagonal and it runs the other way. That is the entire trick behind reverse, and it is why each side needs two direction pins, IN1 and IN2, rather than one.

An H-bridge: four switches with the motor across the middle. Closing the top-left and bottom-right switches drives current one way through the motor; the other diagonal drives it the other way.+ BATTERYGNDMS1S2S3S4OUT1OUT2

IN1 HIGH, IN2 LOW. S1 and S4 close. Current runs from the battery through the motor left to right, and it turns one way.

IN1 LOW, IN2 HIGH. The other diagonal, S2 and S3. Current crosses the motor right to left, and it turns the other way.

IN1 and IN2 the same (shown: both LOW, so S3 and S4 close). Both motor leads are tied together. The spinning motor’s own current loops back through it and stops it fast.

ENA at 0. Every switch opens. The motor is cut loose and freewheels to a stop.

Tap a state. The L298N has two of these bridges, one per motor channel.
IN1IN2Motor A
HIGHLOWturns one way
LOWHIGHturns the other way
LOWLOWbrakes to a stop
HIGHHIGHbrakes to a stop

That is with ENA driven. Set ENA to 0 instead and the motor is cut loose and coasts, which is what stopMotors() in the sketch below does. IN3 and IN4 do the same for motor B. Which way counts as “forward” depends only on which way round the motor leads sit in the screw terminal.

Wiring it to the Arduino

Six male-to-female jumper wires, straight across:

Arduino pinL298N pinWhat it does
5ENAspeed, left side
6ENBspeed, right side
9IN4direction
10IN3
11IN2
12IN1
Step 2 — motor driver to the Arduino Six jumper wires run straight across from the Arduino Uno to the L298N motor driver. Two speed wires: Arduino pin 5 to ENA and pin 6 to ENB, both of which must be PWM-capable pins. Four direction wires: pin 9 to IN4, pin 10 to IN3, pin 11 to IN2 and pin 12 to IN1. /// SPEED (PWM) /// DIRECTION ARDUINO UNO L298N DRIVER 5 6 9 10 11 12 ENA ENB IN4 IN3 IN2 IN1 Take the two jumper caps off the L298N's ENA and ENB headers. Left on, they tie the enables high and the speed buttons do nothing.
The same six wires as the table, straight across.

IN1–IN4 choose direction. ENA and ENB control speed, and they only work on Arduino pins that can do PWM — switching on and off fast enough that the motor averages it out. That is why they sit on pins 5 and 6 rather than anywhere convenient.

The two jumpers, and only one of them matters here

The board ships with small jumper caps on it, and they are not the same jumper. Confusing them is why speed control gets blamed on the sketch.

Close-up of the L298N jumpers: the caps on ENA and ENB must come off; the 5V-enable jumper beside the power terminal stays on.5V-enable jumper: leave it onENA / ENB caps: pull both off
From the module photo above. The two coral caps are why “speed does nothing”; the teal jumper is the one to leave alone.

The ENA / ENB caps — pull these off. Most boards arrive with a cap bridging each enable pin to +5V. That ties the enables permanently high and overrides whatever the Arduino sends. Every speed then behaves as full speed, and no change to the code makes the slightest difference. On the reference car with both caps removed, speed 1 crawls and speed 9 runs — which is only possible with them off.

The 5V-enable jumper — leave this one alone. Different jumper, different job: it feeds the board’s onboard regulator from the main supply. It only has to come off when you power the board above 12V, at which point you supply 5V separately. This car runs on two 18650 cells, so it never gets near that. Leave it on.

Powering it

The battery holder’s red lead goes into +12V and black into GND, screwed down. Then the same two leads go across to the Arduino as well:

Battery leadL298NArduino
Red ++12VVin
Black −GNDGND
Battery holder wired to the L298N +12V and GND terminals, with the same two leads continuing to the Arduino Vin and GND pins
Red to +12V and Vin; black to GND on both boards.

That second pair does two jobs at once. It powers the Arduino, so the car does not die the moment you unplug the USB cable. And it gives the two boards a shared ground, which is what lets the driver understand the signals from the six wires above. Without it the wiring looks perfectly correct and nothing works.

Polarity destroys this board. Red to +12V, black to GND. The wrong way round kills the driver outright. Wire the battery last, every time, and check it twice — it is the only step in the whole build that can damage anything.

Test it: L298N Arduino code

Before the Bluetooth code goes on, prove the driver and the wiring on their own. This sketch uses the exact pins in the table above: it ramps both sides forward from slow to full speed, stops, reverses, stops, and repeats. Lift the car off the table first.

// L298N test: the same pins as the Troniction car.
#define enA 5   // speed, left side  (PWM)
#define enB 6   // speed, right side (PWM)
#define in1 12
#define in2 11
#define in3 10
#define in4 9

void forward() {
  digitalWrite(in1, LOW);  digitalWrite(in2, HIGH);
  digitalWrite(in3, HIGH); digitalWrite(in4, LOW);
}

void backward() {
  digitalWrite(in1, HIGH); digitalWrite(in2, LOW);
  digitalWrite(in3, LOW);  digitalWrite(in4, HIGH);
}

void stopMotors() {
  analogWrite(enA, 0);
  analogWrite(enB, 0);
}

void setSpeed(int speed) {   // 0 to 255
  analogWrite(enA, speed);
  analogWrite(enB, speed);
}

void setup() {
  pinMode(enA, OUTPUT); pinMode(enB, OUTPUT);
  pinMode(in1, OUTPUT); pinMode(in2, OUTPUT);
  pinMode(in3, OUTPUT); pinMode(in4, OUTPUT);
  stopMotors();
}

void loop() {
  forward();
  for (int s = 100; s <= 255; s += 5) {   // slow to full speed
    setSpeed(s);
    delay(60);
  }
  delay(1000);
  stopMotors();
  delay(1000);

  backward();
  setSpeed(180);
  delay(2000);
  stopMotors();
  delay(2000);
}

If the ramp at the start does nothing visible and the car goes straight to full speed, the ENA/ENB caps are still on. If one side runs backwards, swap that side’s two leads in its OUT terminal. The full car sketch, with Bluetooth, is step 3 of the build guide.

When it does not work

What you seeMost likely cause
Nothing moves; the red power LED is onNo shared ground between the L298N and the Arduino, or ENA/ENB not connected to pins 5 and 6
Nothing moves; no LEDNo power reaching +12V/GND: check the battery switch, the cells, and that the screws are clamping bare wire, not insulation
Motors only ever run at full speedThe ENA/ENB jumper caps are still on
One side runs backwardsThat side’s motor leads are swapped in its OUT terminal
Motors hum but do not turnSpeed value too low for the motors to start, or the battery is low; remember the driver takes about 2V first
The Arduino resets when the motors startThe battery sags under load and the Uno browns out; charge the cells
The chip gets hotNormal in use; this is a lossy driver and the heatsink is there for it

L298N voltage drop: the 2V it takes

An H-bridge is not free. The L298N drops roughly 2V across it, so the motors never see the full pack voltage — with the 7.4V pack in this build they get about 5.4V, which lands neatly inside the TT motors’ 3–6V rating.

What reaches the motors: two 18650 cells give 7.4V, minus 2V in the driver leaves 5.4V, inside the TT motors’ 3 to 6V rating. Three cells give 11.1V and leave about 9.1V, well above it.TT MOTOR RATING 3–6V2 × 18650 = 7.4V (this car)5.4V at the motors−2V3 × 18650 = 11.1V9.1V at the motors−2V0V3V6V9V12V
The driver’s 2V is why two cells, not three.

That is the real reason this car uses a two-cell pack rather than three. Three 18650s would be 11.1V; take 2V off and the motors would still see around 9V, against a 6V rating. The chassis and gear motors page has the same arithmetic from the motor’s side.

An honest note about the battery

Two 18650 cells are 7.4V nominal, 8.4V fully charged. The Uno’s recommended Vin range is 7–12V, so this car spends its life at the very bottom of that range. It works — the reference car has run this way for years — but it means the Arduino browns out well before the cells are actually flat. If the car starts behaving strangely, charge it before you start debugging it.

Which one to buy

Get the screw-terminal version, around $8. That is the part that keeps this build solder-free: the motor leads and the battery leads land in the terminal block and are tightened with a small Phillips screwdriver. Boards sold without that block need an iron, and there is no soldering anywhere else in this car.

The L298N motor driver module, screw-terminal version

L298N specifications

For the module as it is sold, for reference rather than reading. These are the sellers’ figures, not ST’s: the L298 chip itself is rated to 46V and 4A in total, and the module’s lower 35V ceiling comes from the two 35V capacitors on the board.

SpecValue
Logic voltage5V
Drive voltage5V – 35V
Logic current0 – 36mA
Drive current2A max per bridge
Max power25W
Size / weight43 × 43 × 27mm, 30g

Download the L298 datasheet if you want STMicroelectronics’ own document, or read the datasheet explained. It covers the chip only; the red module around it has no official datasheet.

Where this fits

Three parts decide how this car behaves: the Arduino Uno makes the decisions, the L298N does the pushing, and the HC-06 listens to your phone. What it pushes is on the chassis and gear motors page, and what powers it on 18650 cells. The wiring itself is step 2 of the build guide; every part has a page, and the whole build is free to read.

Every part of the car

Common questions

Should I remove the ENA and ENB jumpers on the L298N?
Yes, if you want speed control from the Arduino. The caps tie ENA and ENB to 5V, which holds both channels at full speed whatever the Arduino sends. Pull them off and wire ENA and ENB to PWM pins, as this car does with pins 5 and 6.
What does the 5V jumper on the L298N do?
It lets the onboard regulator make 5V for the board's logic from the motor supply. Leave it on for supplies up to 12V. Remove it above 12V and supply 5V to the +5V pin yourself.
Can an L298N drive four motors?
Yes, as two pairs. It has two channels; wire the two left motors in parallel to one and the two right motors to the other. Each pair then turns together, which is exactly what a car needs.
Why are my motors slower on the L298N than on the battery directly?
The L298N drops roughly 2V across itself. With a 7.4V pack the motors see about 5.4V. That loss is normal for this chip.
Do the L298N and the Arduino need a common ground?
Yes. Without a wire between the two GND pins the driver cannot read the Arduino's signals, and the wiring looks correct while nothing moves.

Build it. Understand it.

Get the complete illustrated guide and start your first car — free.

Get the Book