Raspberry Pi L298N motor controller

From wikiluntti
Revision as of 15:55, 12 November 2025 by Mol (talk | contribs) (→‎Connections)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Introduction

RPi is powered by 5V, but on board it is reduced to GPIO 3.3V (GPIOs) and processors and memory (1.8V).

If needed to connect a 5V sensor to Pi, first reduce the 5V to 3.3V by using eg 2 resistors as voltage divider.

However, note that in the digital line the 1 bit is at __V.

L298N

Connections

Shared ground.


  • L298N VCC → External 5-12V power supply (positive)
  • L298N GND → Power supply ground AND Pi 5 ground pin
  • L298N 5V → Pi 5 5V pin (only if using 12V motor supply)

Control Connections:

  • L298N IN1 → Pi 5 GPIO 18
  • L298N IN2 → Pi 5 GPIO 19
  • L298N IN3 → Pi 5 GPIO 20
  • L298N IN4 → Pi 5 GPIO 21
  • L298N ENA → Pi 5 GPIO 12 (PWM)
  • L298N ENB → Pi 5 GPIO 13 (PWM)

Motor Connections:

  • OUT1/OUT2 → Motor A terminals
  • OUT3/OUT4 → Motor B terminals

Python

Install the GPIO package

sudo apt install python3-rpi.gpio

1

1

1

1

1

1

References