23 August 2026 · Bharat Raj · originally published on Compoden
The H-Bridge: How a Motor Learns to Reverse

An H-bridge is an arrangement of four electronic switches around a motor that lets you steer current through the motor in either direction, and since a DC motor's rotation follows its current direction, the bridge is how a motor learns to reverse. Drawn on paper, the four switches and the motor form a letter H: two switches on the left leg, two on the right, motor as the crossbar. Close the top-left and bottom-right switches and current crosses the motor left to right; close the other diagonal and it crosses right to left. Add PWM on the switches and you control speed as well as direction. Every robot that backs up, every camera slider that returns home, has an H-bridge, often the maker favourite L298N, doing this quietly.
Why reversing needs four switches
A single transistor, as covered earlier in this series, switches a motor on and off, but the current always flows the same way, so the motor only ever runs forward. Reversal requires the voltage across the motor to flip polarity, and with a single supply the only way to flip polarity across a load is to swap which of its two terminals connects to positive and which to ground. That takes a switch to positive and a switch to ground on each terminal: four switches, the H.
Name them by corner: high-side left (HL), low-side left (LL), high-side right (HR), low-side right (LR). Forward: HL and LR closed, current flows supply → left terminal → motor → right terminal → ground. Reverse: HR and LL closed, the path mirrors, and the motor spins the other way. Open all four and the motor coasts freely. Close both low-side switches and the motor's terminals are shorted together, which drags a spinning motor to a stop as its own generated voltage drives current against its motion: the useful trick called brake mode.
The forbidden state: shoot-through
One combination must never happen: both switches on the same leg closed at once (HL with LL, or HR with LR). That connects the supply straight to ground through two transistors with no motor in the path, a dead short limited only by how fast something burns. It is called shoot-through, and it is why nobody drives four discrete transistors from four independent pins for long. Integrated H-bridge chips build the interlock in: the L298N takes a direction pair (IN1, IN2) plus an enable pin per motor, and its internal logic makes the illegal state unreachable from the inputs. This is the strongest argument for a driver module over a homemade bridge while learning.
Speed control rides on top
Direction comes from which diagonal is active; speed comes from PWM. Pulse the enable pin (or the active switch pair) and the motor receives its supply in fast slices; its winding inductance and mechanical inertia average the slices into smooth, adjustable torque, exactly the PWM story from earlier in this series. Because the motor is inductive, every H-bridge needs flyback protection; bridge chips route the switch-off spikes through clamp diodes, included on L298N boards.
Worked example: one motor, an Uno, and an L298N
Wire a small DC motor to the L298N motor driver's OUT1 and OUT2 screw terminals. Power: a 6 to 12V battery pack to the driver's VMS/12V terminal, battery negative to the driver's GND, and one Dupont jumper wire from that same GND to the Arduino Uno R3's GND, the common-ground rule in action. Control: IN1 to pin 7, IN2 to pin 8, ENA to PWM pin 9.
The truth table in code: IN1 HIGH with IN2 LOW spins forward; swap them for reverse; both LOW coasts; both HIGH brakes. analogWrite(9, 180) sets roughly 70% speed on whichever direction is active. In twenty lines you have a motor that ramps up, cruises, reverses, and brakes on command. One honest note about the L298N: it is an old bipolar-transistor design that drops around 2V inside itself, so a 7.4V pack delivers only about 5.4V to the motor, and the chip's heatsink earns its keep. Fine for learning and light robots; larger builds graduate to MOSFET-based drivers.
Where this bites you
The most frequent H-bridge complaint is "my motor only runs one way", and the cause is usually code, not hardware: setting IN1 without ever driving IN2, or copying an example that toggles only one pin. Direction is the pair's relationship, not one pin's level. The second classic is a motor that refuses to move at all while the driver LED glows, which is the enable pin: many L298N boards ship with a jumper on ENA holding it permanently HIGH; remove the jumper to use PWM and forget to connect the pin, and the bridge is disabled, silently.
The third bite is expecting battery-voltage performance through the L298N's internal drop, then wondering why a robot crawls. Measure across the motor terminals while running: the missing 2V is inside the chip, warming the heatsink. Budget for it when choosing the pack, or choose a modern driver.
And a habit worth forming immediately: never flip direction at full speed in code without a moment of coast or brake in between. The reversal slams the motor's stored energy and inrush current through the bridge; small setups survive it, but the graceful stop-then-reverse pattern is what keeps drivers alive as motors get bigger.
FAQ
Can one L298N really drive two motors?
Yes, it contains two full H-bridges: OUT1/OUT2 for one motor, OUT3/OUT4 for the second, each with its own direction pins and enable. That is why it became the default driver for two-wheeled robots. The current rating (around 2A per channel with cooling) is shared per bridge, not per board, so check your motors' stall current against it.
Do servos and stepper motors need H-bridges too?
An SG90 servo contains its own driver and takes a pulse signal directly, no bridge needed from you. Bipolar stepper motors are driven by two H-bridges energised in sequence, which is exactly what stepper driver boards contain; the L298N itself can drive a small stepper this way, wired as its two bridges.
What is the difference between coast and brake?
Coast opens all switches: the motor is disconnected and spins down on friction alone. Brake shorts the motor's terminals through the bridge, so the spinning motor generates current that opposes its own rotation and stops it quickly. Robots use brake for crisp stops and coast for gentle ones; try both and you will feel the difference in the chassis.
Describe the robot you want to Compoden's AI build assistant Soldr and it will wire the H-bridge, the grounds, and the code for both directions into one coherent build.