Wiring guide

How to wire an L298N motor driver to a Raspberry Pi Pico

To wire an L298N motor driver to a Raspberry Pi Pico, connect IN1 to GP15 (physical pin 20); IN2 to GP14 (physical pin 19); 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 L298N reads 2.3 V and up as high, so the board’s 3.3 V pins drive IN1 and IN2 directly. 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.

  • 3.3 V logic
  • Library: none
  • 7 wires, 3 helper parts
Raspberry Pi Pico · 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 Raspberry Pi Pico 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 pinRaspberry Pi Pico pinWire colorWhy
IN1GP15 (physical pin 20)greenWith IN2, sets the direction: IN1 high and IN2 low turns the motor one way.
IN2GP14 (physical pin 19)violetIN2 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 Raspberry Pi Pico

Logic level

The Raspberry Pi Pico’s GPIO pins are 3.3 V logic and are not 5 V tolerant. Nothing wired to a pin may go above 3.3 V.

This pair

The Raspberry Pi Pico’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 3.3 V signals work directly even from a 3.3 V pin. 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

The numbers in the code are GP numbers, not the physical pin numbers printed beside the header: GP15 is pin 20. GP23 to GP25 are used on the board itself, and GP25 is the LED.

The sketch

The working code for the Raspberry Pi Pico

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

L298N forward and reverse on Raspberry Pi Pico GP15 (physical pin 20), GP14 (physical pin 19)
const int IN1 = 15;   // GP15 (physical pin 20)
const int IN2 = 14;   // GP14 (physical pin 19)

void setup() {
  Serial.begin(115200);
  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 115200 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 a Raspberry Pi Pico

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 Raspberry Pi Pico’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.