Wiring guide

How to wire an L298N motor driver to an Arduino Uno

To wire an L298N motor driver to an Arduino Uno, connect IN1 to pin 2; IN2 to pin 3; GND to GND; 12V to The 9 V motor supply; and OUT1, OUT2 to The motor’s two terminals. The motor runs from its own 9 V supply on the 12V terminal and the board only drives the two inputs, so its 5 V pins need no shifting. The sketch below uses no library beyond what the board includes. It runs the motor forward for a second, stops, reverses for a second and stops, printing each step.

  • 5 V logic
  • Library: none
  • 7 wires, 3 helper parts
Arduino Uno · L298N motor driverlive0.000 s 0.00x
Click to open it in the editor
The circuit itself, running on the simulator with the sketch below. Press what can be pressed; click anything else to open it in the editor.
Pin to pin

L298N motor driver to Arduino Uno wiring table

Every wire in the circuit above, with the part’s pin names and the board’s own labels. The wire colors are the ones the circuit uses; on a real bench any colors work.

L298N motor driver pinArduino Uno pinWire colorWhy
IN1pin 2greenWith IN2, sets the direction: IN1 high and IN2 low turns the motor one way.
IN2pin 3violetIN2 high and IN1 low turns it the other way; both low lets it coast.
GNDGNDblueThe board and the driver must share a ground, and so must the motor supply: all three grounds are one net.
12VThe 9 V motor supplyredThe motor’s own supply, not the board’s: the driver passes it on to the motor.
OUT1, OUT2The motor’s two terminalsamber, cyanSwap the two wires and the motor turns the other way for the same signals.
ENA (jumper)Jumper left onn/aWith the jumper on, channel A is always enabled. Remove it to give ENA a pin and set the speed with analogWrite().
Voltage

Power and logic levels for L298N motor driver and Arduino Uno

Logic level

The Arduino Uno’s pins are 5 V logic. A 5 V part can drive them directly; a part whose signal pins are limited to 3.3 V needs a level shifter.

This pair

The Arduino Uno’s pins only drive the two inputs, a few milliamps; the motor’s current comes from its own supply on the 12V terminal. The L298N reads 2.3 V and up as high, so 5 V signals work. The bridge drops about 2 V, so a 9 V supply gives the motor about 7 V. Ground must be shared by the board, the driver and the supply.

Pins to leave alone

Pins 0 and 1 are the USB serial port on a real Uno, so anything wired there fights the upload and the serial monitor. Pin 13 carries the onboard LED.

The sketch

The working code for the Arduino Uno

Library: none, the sketch sets the direction with digitalWrite(). This is the sketch the circuit above runs.

L298N forward and reverse on Arduino Uno pin 2, pin 3
const int IN1 = 2;   // pin 2
const int IN2 = 3;   // pin 3

void setup() {
  Serial.begin(9600);
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);
}

void loop() {
  digitalWrite(IN1, HIGH);   // IN1 high, IN2 low: forward
  digitalWrite(IN2, LOW);
  Serial.println("Forward");
  delay(1000);

  digitalWrite(IN1, LOW);    // both low: the motor coasts
  digitalWrite(IN2, LOW);
  Serial.println("Stop");
  delay(500);

  digitalWrite(IN1, LOW);    // IN1 low, IN2 high: reverse
  digitalWrite(IN2, HIGH);
  Serial.println("Reverse");
  delay(1000);

  digitalWrite(IN1, LOW);
  digitalWrite(IN2, LOW);
  Serial.println("Stop");
  delay(500);
}
Output

What you should see

The motor turns one way for a second, stops for half a second, turns the other way for a second and stops. The serial monitor, at 9600 baud, prints Forward, Stop, Reverse and Stop.

A motor that does not move usually has no common ground between the board, the driver and the supply, or the supply is too low once the bridge has dropped about 2 V.

The serial monitor prints this, recorded from the circuit above running for three and a half seconds:

Forward
Stop
Reverse
Stop
Forward
Pitfalls

Common mistakes wiring an L298N motor driver to an Arduino Uno

Forgetting the common ground

The inputs are measured against the driver’s ground. With the board’s ground not joined to it, the signals mean nothing and the motor does not turn or twitches at random.

Powering the motor from the board

A motor takes far more current than the Arduino Uno’s pins or its 5V pin can give. Use a separate supply on the 12V terminal, and join the grounds.

Expecting the full supply voltage at the motor

The L298N’s bridge drops about 2 V, so a 6 V motor on a 6 V supply runs slowly. Use a supply about 2 V above the motor’s rating.

Build your own L298N motor driver project

Open this circuit in the editor, change the wiring or the code, and keep your version in a free account.