Lab

The H-bridge: four switches, one motor

A DC motor turns one way when current goes through it one way, and the other way when it goes through the other way. The L298N motor driver swaps that direction with four switches arranged like the letter H, the motor across the middle. Each side of the car has one of these bridges.

Start with IN1 HIGH and IN2 LOW and follow the current. Then swap them and watch the same motor turn the other way. Then set both HIGH, and then switch ENA off: two different ways to stop.

Last, tap the car’s letters. Each one is just a pattern on the four IN pins.

IN1
IN2
ENA (BRIDGE ON)
ONE SIDE OF THE L298N: FOUR SWITCHES, THE MOTOR ACROSS THE MIDDLE
battery + (7.4 V)groundIN1 HIGHclosedIN1 LOWopenIN2 HIGHopenIN2 LOWclosedOUT1OUT2Mturns one way
The motor turns one way.
IN1 HIGH ties OUT1 to the battery’s plus; IN2 LOW ties OUT2 to ground. Current crosses the motor from left to right.
The current passes through two closed switches, and each keeps a little voltage for itself: about 2 V for the pair, so the motor gets about 7.4 − 2 = 5.4 V. The 2 V becomes heat in the chip, which is why the fins get warm. (The datasheet gives 1.8–3.2 V at 1 A; 2 V is a working estimate at these currents, not a reading.)
THE CAR'S LETTERS (SIDE A IS THE BRIDGE ABOVE)
letterIN1IN2IN3IN4side Aside B
FLHHLforwardforward
BHLLHbackwardbackward
LHLHLbackwardforward
RLHLHforwardbackward
SHHHHbrakebrake
Tap a letter. It sets side A’s two pins in the bridge above. Side B is the same circuit on IN3 and IN4.
H = HIGH, L = LOW. Side A goes forward on LOW, HIGH and side B on HIGH, LOW: the two sides’ motors face opposite ways, and the sketch matches the wires, not a rule.
NOW YOU TRY
IN1 and IN2 are both HIGH. What does the motor do? Is that the same as ENA being off?
Say your answer out loud, then open this
It brakes: both ends of the motor are tied to plus, so the spinning motor’s own current loops round and stops it fast. ENA off is different: every switch opens and the motor coasts. Set both, one after the other, above and compare. The car’s S uses the brake.

What this shows

An H-bridge is four switches in a square with the motor across the middle, drawn like the letter H. Closing the top-left and bottom-right switches sends current through the motor one way; closing the other diagonal sends it the other way. The motor never changes, only the path through it.

On the L298N each IN pin decides one end of the motor: IN1 HIGH ties OUT1 to the battery's plus, IN1 LOW ties it to ground, and IN2 does the same for OUT2. HIGH and LOW turn the motor one way, LOW and HIGH the other way. ENA switches the whole bridge on or off, so each motor channel needs three control pins, not four.

Both IN pins the same, with ENA on, is a brake: both ends of the motor are tied together, and a spinning motor's own generated current loops round and stops it fast. The datasheet calls it fast motor stop. ENA off opens every switch and the motor coasts: free running motor stop.

The current passes through two switches, and each keeps a little voltage. The L298 datasheet gives 1.8 to 3.2 V lost at 1 A; about 2 V is a working estimate at a small car's currents, so from 7.4 V the motors get about 5.4 V and the 2 V becomes heat in the chip.

In the Troniction car's sketch, F is LOW, HIGH, HIGH, LOW on IN1 to IN4; B is HIGH, LOW, LOW, HIGH; L is HIGH, LOW, HIGH, LOW; R is LOW, HIGH, LOW, HIGH; and S, or any other letter, sets all four HIGH to brake both sides.

Common questions

How does an L298N H-bridge reverse a motor?
It has four switches around the motor. IN1 and IN2 choose which end of the motor connects to the battery's plus and which to ground. Swap them and the current crosses the motor the other way, so it turns the other way.
What happens when IN1 and IN2 are both HIGH?
With ENA on, the motor brakes: both its ends are tied to the same point, and its own generated current stops it fast. Both LOW brakes too. That is different from ENA off, which opens every switch and lets the motor coast.
Why does the L298N get hot?
Its switches are transistors that keep about 2 V for themselves at a small car's currents (the datasheet gives 1.8 to 3.2 V at 1 A). That lost voltage times the current is heat in the chip. A stalled motor draws the most current and heats it most.