L298N motor driver module

The red board with the black heat sink that drives the two wheels of nearly every robot car.

It is an L298 dual H bridge, a 5 V regulator, clamp diodes and three jumpers.

Two DC motors, each turned either way at a speed set by PWM, or one bipolar stepper such as the NEMA 17 in full step. Most of what goes wrong with this board is one of its jumpers, so the jumpers are properties here and are drawn on the board when they are fitted.

Pins

Pin What it does
OUT1, OUT2 Motor A's screw terminal.
OUT3, OUT4 Motor B's screw terminal.
12V The motor supply, VS on the chip: 4.8 V up to 46 V.
GND Ground, shared with the board that drives the inputs.
5V The logic supply: an output with the regulator jumper fitted, an input without it.
ENA, ENB Enables for motor A and motor B. High drives, low lets go.
IN1, IN2 Motor A's direction.
IN3, IN4 Motor B's direction.

Properties

regulator: whether the 5 V regulator jumper is fitted (it is, out of the bag). ena_jumper, enb_jumper: whether ENA and ENB are tied high by their jumpers (they are, out of the bag).

Driving it

EN IN1 IN2 motor A
low either either both outputs let go: it coasts
high high low forward
high low high reverse
high same same both ends together: a brake

IN3, IN4 and ENB do the same for motor B. For speed, pull the ENA jumper off and give ENA a PWM pin: analogWrite(ENA, 128). With the jumper fitted, ENA is strapped to the 5 V rail and the motor only ever runs at full speed.

The three jumpers

The 5 V regulator. Fitted, the 78M05 on the board makes the logic supply out of the motor supply and the 5V terminal becomes an output, which is how a robot car powers its Arduino off the same battery. A 78M05 needs about 2 V of headroom, so the motor supply has to be 7 V or more. On a 6 V pack it makes 4 V, the L298 wants 4.5 V for its logic, and nothing turns. Removed, 5V is an input and has to be given 5 V from somewhere: the board's own 5 V pin is the usual answer.

ENA and ENB. Fitted, the motor is always enabled. Removed, the enable is a pin and a floating one is off.

What the model gets right

The volts the bridge keeps for itself. The L298 is a bipolar chip, and its datasheet gives 1.35 V lost in the high side and 1.2 V in the low side at 1 A, so a motor on a 12 V supply sees about 9.5 V and one on a 7.4 V pack under 5 V. That is modeled, as a source 1.35 V under the rail and a sink 1.2 V over ground, each with a little resistance on top. Braking falls out of the model: both outputs at the same place short the motor's back EMF and it stops fast, where letting go of both lets it coast. The regulator's 2 V of dropout, and the logic dying under 4.5 V, are both there. Past 46 V the outputs go dead rather than drive.

What it does not model

Current and heat. The L298 is rated 2 A a channel and the module ties its current sense pins to ground, so there is no limit here either; nothing gets hot, and there is no thermal shutdown. The advice printed on the module to pull the regulator jumper above 12 V is about the 78M05's heat, which is not modeled, so here it keeps working at 20 V. The regulator itself is a source two volts under the motor supply capped at 5 V, with no load regulation. The eight clamp diodes are on the board but not in the model: the DC motor has no inductance, so there is no kick for them to catch. The chip's switching speed, which makes PWM above about 25 kHz pointless on a real one, is not modeled.

Common mistakes

Powering the board from a 6 V pack with the regulator jumper on, and finding the motors never turn. Leaving the ENA and ENB jumpers on and wondering why analogWrite changes nothing. Forgetting to join the module's GND to the Arduino's, so the inputs have nothing to be high against.

See it in action

Robot car drive runs two gearbox motors from an Uno through one of these. Open it at /templates.