L298N Motor Driver Tutorial

L298N Motor Driver Tutorial 🔧 Forward, Reverse & PWM Speed Control | Arduino for Kids
🔧 ROBOTICS FOR KIDS · LEVEL: BEGINNER

L298N Motor Driver: Basics, Direction & Speed Control

Meet Torque — your friendly guide to the L298N, the most popular motor driver for beginners! In three easy parts, you'll learn how to wire it up, spin a motor forward and backward, and control exactly how fast it spins using PWM.

⏱️ 1–2 hours 🎂 Ages 9+ (with an adult) 📘 3-Part Tutorial

⚙️ Say hi to Torque, your motor driver guide!

What Is an L298N Motor Driver, Anyway?

An Arduino pin can only supply a tiny trickle of current — nowhere near enough to spin a real DC motor safely. The L298N solves this problem: it's a small board that takes a little signal from the Arduino and uses it to switch a much bigger current from a separate battery to the motor. It can also flip that current's direction, which is how a motor spins forward or backward.

This tutorial covers three essential skills in order: Part 1 wiring the L298N and spinning a motor, Part 2 controlling forward and reverse direction, and Part 3 controlling motor speed with PWM.

🧰

What You'll Need

The same simple setup is used for all three parts of this tutorial.

x1

Arduino Uno

Sends direction and speed signals to the L298N.

x1

L298N Motor Driver Module

The star of this tutorial — controls the motor safely.

x1

Small DC Motor

The motor you'll spin forward, backward, and at different speeds.

x1

Potentiometer (10kΩ)

Used in Part 3 to manually dial in motor speed.

x1

4x AA Battery Pack (or 9–12V supply)

Powers the motor — separate from the Arduino's own power.

x1

Breadboard

For connecting everything without soldering.

~10

Jumper Wires

Male-to-male and male-to-female.

🔌

The Circuit Diagram

This same wiring is used for all three parts — only the code changes!

Arduino Uno UNO Pin 8 — IN1 Pin 9 — IN2 Pin 10 — ENA (PWM) A0 — Potentiometer Wiper 5V GND L298N Motor Driver IN1, IN2, ENA OUT1, OUT2 → Motor 12V + GND → Battery Pack Shares GND with Arduino DC Motor Potentiometer 4x AA Battery Pack
IN1 → pin 8 · IN2 → pin 9 · ENA → pin 10 Motor → OUT1/OUT2 on the L298N Battery pack → L298N's 12V + GND terminals Potentiometer wiper → A0 (for Part 3)
1️⃣

Part 1: L298N Basics — Spinning the Motor

Let's start simple: wire everything up and get the motor spinning in one direction.

1

Wire the Arduino to the L298N

Connect Arduino pin 8 to IN1, pin 9 to IN2, and pin 10 to ENA. Connect Arduino GND to the L298N's GND.

2

Wire the motor and battery pack

Connect your DC motor to OUT1 and OUT2. Connect the battery pack's positive and negative wires to the L298N's 12V and GND screw terminals.

💡 Tip: Never power the motor from the Arduino's 5V pin directly — motors need their own separate power source!
l298n_part1_basics.ino
// 🔧 Part 1: L298N Basics — spin a motor forward at full speed

const int IN1 = 8;
const int IN2 = 9;
const int ENA = 10;

void setup() {
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);
  pinMode(ENA, OUTPUT);
}

void loop() {
  digitalWrite(IN1, HIGH);   // current flows one way through the motor
  digitalWrite(IN2, LOW);
  digitalWrite(ENA, HIGH);   // ENA high = motor runs at full speed
}
2️⃣

Part 2: Forward & Reverse Control

Now let's make the motor spin one way, then the other — the wiring stays exactly the same as Part 1!

1

Understand the IN1/IN2 pattern

The L298N flips the motor's direction based on which of IN1 and IN2 is HIGH. Swapping which one is HIGH reverses the current, which reverses the spin.

l298n_part2_forward_reverse.ino
// 🔄 Part 2: Forward and Reverse — alternates direction every few seconds

const int IN1 = 8;
const int IN2 = 9;
const int ENA = 10;

void setup() {
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);
  pinMode(ENA, OUTPUT);
  digitalWrite(ENA, HIGH);   // keep speed at full for this part
}

void loop() {
  spinForward();
  delay(3000);
  stopMotor();
  delay(500);

  spinReverse();
  delay(3000);
  stopMotor();
  delay(500);
}

void spinForward() {
  digitalWrite(IN1, HIGH);
  digitalWrite(IN2, LOW);
}

void spinReverse() {
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, HIGH);
}

// Setting both IN pins LOW lets the motor coast to a stop
void stopMotor() {
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, LOW);
}
3️⃣

Part 3: PWM Speed Control

Instead of just full-speed on or off, let's control exactly how fast the motor spins using a potentiometer knob!

1

Add the potentiometer

Connect the potentiometer's two outer pins to 5V and GND, and its middle pin (the wiper) to Arduino pin A0.

💡 Tip: ENA must be connected to a PWM-capable pin (marked with a ~ symbol on your Arduino) for speed control to work!
l298n_part3_pwm_speed.ino
// 🎚️ Part 3: PWM Speed Control — turn the knob to change motor speed

const int IN1 = 8;
const int IN2 = 9;
const int ENA = 10;
const int potPin = A0;

void setup() {
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);
  pinMode(ENA, OUTPUT);

  digitalWrite(IN1, HIGH);   // direction fixed as forward for this demo
  digitalWrite(IN2, LOW);
}

void loop() {
  int potValue = analogRead(potPin);         // reads 0–1023
  int motorSpeed = map(potValue, 0, 1023, 0, 255);  // scale to PWM range

  analogWrite(ENA, motorSpeed);   // smoothly changes the motor's speed
}
🧠

How Does the L298N Actually Work?

Here are the big ideas hiding inside this tutorial:

🌉

The H-Bridge

Inside the L298N is a circuit called an H-bridge, which can route current through the motor in either direction — that's the real trick that makes forward and reverse possible.

🔌

Separating Logic from Power

The Arduino's small signals (IN1, IN2, ENA) only tell the L298N what to do — the actual motor power comes from the separate battery pack, keeping the Arduino safe.

🎚️

PWM: Fast On/Off Switching

analogWrite() doesn't create a "half voltage" — it rapidly switches the pin on and off. The more time it spends on versus off, the faster the motor spins, on average.

🎛️

Reading an Analog Knob

The potentiometer gives a changing voltage as you turn it, which analogRead() converts into a number from 0–1023 — map() then rescales that into the 0–255 range PWM understands.

🧑‍🔬 Safety First!

  • Never power a motor directly from the Arduino's 5V pin — always use the L298N with a separate battery pack.
  • Double-check your battery pack's voltage matches your L298N and motor's ratings before connecting.
  • Keep fingers and loose wires clear of the spinning motor shaft.
  • Build with an adult, especially the first time you wire a motor driver.
  • Disconnect power before changing any wiring.

Frequently Asked Questions

My motor doesn't spin at all — what's wrong?

Check that your battery pack is actually connected and has power, that GND is shared between the Arduino and the L298N, and that ENA is set HIGH or receiving a PWM value above 0.

Can I control two motors with one L298N?

Yes! The L298N has a second channel — IN3, IN4, ENB, and OUT3/OUT4 — that works exactly the same way as IN1/IN2/ENA/OUT1/OUT2, letting you control a second motor independently.

What's the difference between ENA being HIGH and using analogWrite()?

digitalWrite(ENA, HIGH) runs the motor at full, constant speed. analogWrite(ENA, value) uses PWM to run it at any speed between fully off (0) and full speed (255).

What age group is this tutorial good for?

This is a great beginner-friendly tutorial for kids around age 9 and up, especially as an introduction to motors before building bigger robots.

🎉 Great work — you've mastered the L298N! You now know how to wire it, control direction, and control speed — the foundation for almost every wheeled robot project.

⬆️ Back to Materials List

Comments

Product Cards
Buddy Bot eBook
⭐ New 2026 Release
Build Your
Own Robot!
3D design, wiring &
Arduino coding.
Young inventors love it!
🖨️
3D Print
All parts
Wire it
Circuit guide
💻
Code it
Arduino IDE
🤖
Watch it
Walk & react
📋 Your Details
Enter your name
Valid 10-digit no.
Enter a valid email
Special Website Offer
₹499 300
🌍 International: $5 USD
One-time · Instant digital delivery
🔒 Secured by Razorpay · Your data is safe
📄 Download Free Sample Copy
🔒 Secured by Razorpay · Your data is safe
🍓
Raspberry Pi Pico Mastery
21 Projects
⚡ Launch Price — 80% OFF
Learn Pico
Build 21 Projects!
MicroPython · Wokwi
IoT · Certificate
Perfect for beginners!
🖥️
Wokwi
No hardware
🐍
MicroPy
From zero
🔨
21 Projects
IoT + sensors
📄
Certificate
Verified cert
📋 Your Details
Enter your name
Valid 10-digit no.
Enter a valid email
Special Launch Offer
₹999 200 80% OFF
🌍 International: $5 USD
One-time · Lifetime access · No subscription
🔒 Secured by Razorpay · UPI · Cards · NetBanking
🎉

You're in!

Payment successful! Your Buddy Bot eBook is ready. Time to build!

📖 Access Your eBook Now
🎉

Enrolled!

Payment successful! Lifetime access to all 21 Pico Projects is yours!

🍓 Go to My Course