Arduino DC Motor Control With L298N

arduino l298n motor driver

Your motor spins, but only one way and only flat out. That is the usual first result with an Arduino L298N motor driver, and you can fix it in stages: direction, then speed, then power.

Quick answer: Set IN1 and IN2 to opposite levels to choose direction. Remove the enable jumper and drive the enable pin with PWM to set speed. Power the motors from a battery pack. A tutorial on the board recommends 6V to 12V and says the 5V jumper must come out above 12V.

This build is one of the arduino robotics projects on the site. It uses a DC motor on channel A and an Arduino Uno as the controller.

Wire the board and spin the motor

The simplest first test leaves every jumper in place and only proves that the wiring works. The L298N drives two DC motors simultaneously, and this guide uses motor A only. Keep the motor and its battery pack away from the Arduino’s USB power while you wire.

The motor’s leads trail across the white surface, and a hand holds a thin black rod next to the housing.
  1. Motor: connect the two motor wires to the motor A screw terminals. Swapping them later is a quick way to flip which direction counts as forward.
  2. Motor power: connect the battery pack’s positive lead to the board’s motor supply terminal and its negative lead to the ground terminal. Join that ground to an Arduino GND pin so the control signals share a reference.
  3. Direction pins: run IN1 to a digital pin on the Uno. One forum build used pin 7 for IN1. Run IN2 to another free digital pin.
  4. Enable: for this first test, leave the jumper cap on the motor A enable pins. The caps are fitted by default and hold the channel enabled.

Set IN1 and IN2 to opposite levels in a short sketch. If the motor turns, the power and control wiring are sound, and you can move on to controlling direction on purpose.

Direction and the H-bridge truth table

The L298N contains an H-bridge for each motor, and the H-bridge lets the driver apply the supply to the motor in either direction. You never reverse the battery leads in software. You change the two input levels instead.

With the enable pin high, input 1 LOW and input 2 HIGH makes motor A spin forward. Input 1 HIGH and input 2 LOW makes it rotate backwards. The table gives the full set for motor A.

Motion Input 1 Input 2 Enable 1 Planning use
Forward 0 1 1 Treat as the default direction, then swap the motor wires if it is backwards for your build.
Backwards 1 0 1 Reverse the input levels: input 1 HIGH and input 2 LOW drives motor A backwards.
Stop 0 0 0 Use this row when the sketch should hold the motor idle.

These truth-table values come from the Random Nerd Tutorials L298N guide.

The enable column is the bridge to the next stage. While the jumper cap holds enable high, you only get direction and full speed. Taking over that pin gives you speed as well.

Speed control with PWM on the enable pin

To control speed, take the jumper cap off the motor A enable pins and feed that pin from the Arduino. The tutorial states plainly that you need to remove those jumper caps to control the speed of your motors.

Control wiring is a handful of short jumper leads from the Arduino to a breadboard. The L298N’s input and enable pins connect the same way.
  1. Remove the cap: pull the jumper from the motor A enable pins.
  2. Move the enable wire to a PWM pin: the forum build above connected UNO pin 9 to enable motor1. Whichever pin you choose, it must support PWM.
  3. Set direction first: write IN1 and IN2 to opposite levels as in the truth table.
  4. Write a duty value with analogWrite: a higher duty cycle gives a faster motor, because motor speed is proportional to the duty cycle.

Speed is therefore a separate lever from direction. The two input pins pick which way the bridge pushes current, and PWM on enable decides how much of each cycle that push is applied. Test with a mid-range value first and step up, so you can see the motor respond.

Colour-coding the wires helps here. Use one colour for each direction pin and a different one for the PWM enable lead, so a swapped wire is easy to spot.

Motor power and the 5V jumper

The motor needs its own supply, not the Arduino’s. A DC motor requires a big jump in current to move, so power it from an external battery pack or supply.

Choosing the supply voltage

The same tutorial says you can supply any voltage between 5V and 35V, but 6V to 12V is the recommended range. Treat the 35V figure as a ceiling, not a target. The tutorial’s example pack uses four 1.5V AA batteries, which combine to approximately 6V. That sits at the low end of the recommended range and suits small hobby motors. It also describes the driver as handling up to 3A at 35V.

Compact dual-channel boards sold under the same name can differ. One vendor listing gives a module supply of DC 2V-10V and a peak current of 2.5A, with working current of 1.5A. Check the rating printed on or listed for your own board before you pick a pack.

AA cells are a handy stand-in for a battery pack when testing. Four in series reach roughly the 6V used in the tutorial example.

When to remove the 5V jumper

The jumper decides where the board’s logic gets its power. With the jumper in place, the chip is powered using the motor’s power supply. That is fine up to 12V and convenient, because you need no separate logic supply.

Remove the jumper when you supply more than 12V, and feed 5V to the +5V terminal instead. Leave it in for a 6V to 12V pack.

When the driver runs hot or the motor sags

Heat and a motor that feels weaker than the pack voltage suggests usually point to the same cause: the driver is carrying a heavier load than it comfortably handles. Work through these checks in order, from least to most disruptive.

  1. Lighten the load: run the motor free of its wheels or gearing and see whether the board stays cool. A motor that is stalled or dragging draws the heaviest current.
  2. Check the supply is sound: a pack that is nearly flat or too small struggles with the start-up jump in current. Use fresh cells or a pack sized to the motor.
  3. Check the rating of your board: compare the motor’s current with the board’s listed limits. The compact board above lists a working current of 1.5A and a peak of 2.5A.
  4. Stay within the voltage guidance: a pack at the top of the range is not an upgrade. Return to 6V to 12V if you have drifted higher.

That compact board’s listing also mentions built-in thermal shutdown (TSD), described as removing the worry about motor stall. Even so, a driver that keeps reaching its limit tells you the motor and driver are mismatched. Stop and choose a driver rated for the motor’s current rather than running it hot. Projects that need exact positioning rather than variable speed are better served by arduino stepper motor control.

Frequently asked questions

Can one L298N run more than one motor?

Yes. The board drives two DC motors simultaneously. Motor B has its own channel, and this guide covered motor A only.

Why does my motor buzz instead of turning?

For small duty cycles, the motors might not spin and make a continuous buzz. Raise the duty value until the motor starts turning.

Why does the motor only run at one speed?

Check the enable jumper first. While the cap is fitted, it overrides your PWM pin. One forum user reported getting only a single speed from analogWrite at 180 on an Uno. The tutorial’s fix for speed control is removing the caps and driving enable from a PWM pin.

Do I need a capacitor across the motor?

It is optional. The tutorial recommends soldering a 0.1uF ceramic capacitor across the motor’s positive and negative terminals.