By Kevin McAleer, 5 Minutes
Page last updated November 24, 2026

By the end of this lesson you will be able to read an H-bridge truth table and choose between forward, reverse, brake and coast.
A DC motor reverses when you swap its two wires. A robot cannot swap wires by hand, so we build a circuit that does it electronically. That circuit is the H-bridge, and it lives inside every motor driver you will use.
Draw the motor in the middle, and a switch at each corner:
+V (motor supply)
| |
[S1] [S2]
| |
+-----(M)----+
| |
[S3] [S4]
| |
GND GND
Real drivers use transistors for the switches, but think of them as little taps. Which ones you close decides what the motor does:
| S1 | S2 | S3 | S4 | Motor |
|---|---|---|---|---|
| on | off | off | on | Current flows left to right: spins forward |
| off | on | on | off | Current flows right to left: spins in reverse |
| off | off | on | on | Both ends tied to ground: brakes |
| on | on | off | off | Both ends tied to +V: brakes |
| off | off | off | off | Nothing connected: coasts |
Never close S1 and S3 together (or S2 and S4). That connects the supply straight to ground, which is called shoot-through, and it destroys the transistors. On the L298N each side of the bridge is driven by a single input, so you cannot command that mistake by accident, and the DRV8833 has built-in protection too. That is a big reason we use driver chips rather than four loose transistors.
Here are the switch states as a little map. Each arrow is one change to the switches:
stateDiagram-v2
[*] --> Coast
Coast --> Forward: S1 and S4 on
Forward --> Brake: S3 and S4 on
Brake --> Reverse: S2 and S3 on
Reverse --> Coast: all switches off
The driver turns those four switches into two pins per motor, IN1 and IN2. The L298N adds a third, EN (enable), which switches the whole bridge on or off. This is the truth table you will code against:
# What does one L298N channel do for each input combination?
def bridge_state(in1, in2, en):
if not en:
return "coast (bridge disabled)"
if in1 and not in2:
return "forward"
if in2 and not in1:
return "reverse"
return "brake (both inputs the same)"
for en in (0, 1):
for in1 in (0, 1):
for in2 in (0, 1):
print("EN", en, "IN1", in1, "IN2", in2, "->", bridge_state(in1, in2, en))
Run it in Thonny and you will see all eight combinations. Keep this in your head, because everything we do for the next five lessons is just choosing these three values.
Scout will use brake when it needs to stop precisely at the corner of a square, and coast when we do not care. Lesson 9 tries both side by side.
The DRV8833 has no EN pin. It has two inputs per motor, and you vary the PWM on those. The truth table collapses to:
| IN1 | IN2 | Motor |
|---|---|---|
| PWM | low | Forward at that speed |
| low | PWM | Reverse at that speed |
| high | high | Brake |
| low | low | Coast |
Same H-bridge, different front door.
bridge_state so it prints “stopped” when both inputs are low and EN is high. Then check against the real driver: does the motor free-wheel (coast) or resist being turned (brake)? What does that tell you about the truth table?Quick quiz 1 of 3
What is shoot-through?
Quick quiz 2 of 3
What is the difference between brake and coast?
Quick quiz 3 of 3
On a DRV8833, how do you run a motor forward at part speed?
Comments