Sub topic 2
The H-bridge: four switches around a motor
Prerequisites and scope
This chapter assumes you know Ohm's law, you can read a simple wiring diagram, and you know that a transistor can act as a switch. It also assumes you know that a brushed DC motor reverses when the voltage across it reverses. Direction states, shoot-through, flyback paths, and PWM each get their own chapters. Here you will learn the structure of the bridge and why it has that structure.
The problem an H-bridge solves
A brushed DC motor has two terminals. Positive voltage on terminal A relative to terminal B spins it one way. Reversing the polarity spins it the other way. An Arduino pin cannot do this directly, for two reasons:
- A pin supplies about 20 mA, and a small motor draws hundreds of milliamps or more.
- A pin can only switch between 0 V and the logic voltage. It cannot swap the polarity of a separate motor supply.
One transistor can switch the motor on and off, but it only ever sends current one way. To reverse the motor you must be able to connect either terminal to the supply and the other terminal to ground. That takes a circuit that can pick each terminal's connection independently.
The four-switch structure
An H-bridge has four switches arranged around the motor. Drawn on paper, the two vertical sides and the motor across the middle look like the letter H.
- The supply (VM, the motor voltage) connects to the top of both sides.
- Ground connects to the bottom of both sides.
- Each side has a high-side switch (between VM and the motor terminal) and a low-side switch (between the motor terminal and ground).
- The motor connects between the midpoints of the two sides.
By convention the switches are named S1 and S2 for the high and low switch on the left side, and S3 and S4 for the high and low switch on the right side. This chapter uses these names:
| Switch | Position | Connects |
|---|---|---|
| S1 | Left, high side | VM to motor terminal A |
| S2 | Left, low side | Motor terminal A to ground |
| S3 | Right, high side | VM to motor terminal B |
| S4 | Right, low side | Motor terminal B to ground |
Each terminal of the motor can be tied to VM through its high-side switch, to ground through its low-side switch, or to neither if both of its switches are open. Four switches give 16 on/off combinations. Only a handful are useful, and a few are dangerous. The next chapters sort them out.
Why both high-side and low-side switches
You might ask why the bridge needs four switches rather than two or three. The answer is that each terminal needs to be pulled in both directions.
- With only low-side switches, you can ground either terminal, but the other terminal has to be wired permanently to VM. Current then flows in only one direction through the motor, so you get on and off but no reversal.
- With a split supply (a positive and a negative rail) you could use one switch per rail on each side of a half bridge. That needs a second supply, which most hobby projects do not have.
- With four switches on a single supply, either terminal can be the more positive one. The motor sees +VM across it in one case and -VM in the other.
So the H-bridge gets a bipolar voltage across the motor from a single-polarity supply.
Half bridges as building blocks
Each side of the H, with one high switch and one low switch and a shared midpoint, is called a half bridge (or a leg). A full H-bridge is two half bridges whose midpoints connect to the two motor terminals.
This is useful because many driver chips are sold in terms of half bridges. A dual H-bridge chip such as the L298N or L293D contains four half bridges and can drive two motors, or one stepper motor. Some drivers can also be wired to use a half bridge to drive a single-direction load. Knowing the leg structure makes datasheets easier to read.
What the switches physically are
The abstract switches become real components in a few ways.
- Bipolar transistors (BJTs, including Darlington pairs) are used in older chips such as the L298N and L293D. They are simple, but they lose around 1 to 2 V across the pair, which wastes power as heat and cuts the voltage the motor gets.
- MOSFETs are used in modern drivers. They behave like a small resistor when on (the on-resistance, RDS(on)), often tens of milliohms or less. Loss is I² × RDS(on), which is much lower than a fixed 1 to 2 V drop.
- Discrete designs use separate MOSFETs plus a gate driver chip. They scale to high currents but need careful design.
High-side MOSFETs add a complication. An N-channel MOSFET on the high side needs its gate voltage above the supply to turn on fully, so many bridge drivers include a charge pump or a bootstrap circuit to generate that voltage. You do not need to design this when using an integrated driver, but it explains why some chips have extra capacitor pins and why some bootstrap-based designs cannot hold 100 percent duty cycle indefinitely.
Driver selection comes later in the series. For now, treat each switch as an ideal switch with some loss.
How the driver translates your logic signals
You do not control four switches with four pins in most modules. A typical driver gives you a simpler interface. Common patterns are:
| Interface | Pins | How it works |
|---|---|---|
| Two direction inputs plus enable | IN1, IN2, EN | IN1 and IN2 choose which switches close. EN gates the output, and a PWM signal on EN sets speed. |
| Two PWM-capable inputs | IN1, IN2 | PWM on one input with the other low drives one direction. Swap them to reverse. |
| Direction plus PWM | DIR, PWM | DIR picks the polarity, PWM sets the duty cycle. |
Inside the chip, logic circuits turn these inputs into gate or base signals for the four switches. The same logic prevents the dangerous combination in which both switches on one side are closed at once. That is one of the main reasons to use an integrated driver instead of driving four transistors from separate pins.
A first look at the code
The two-input-plus-enable pattern maps to code like this. The sketch assumes a driver such as an L298N or L293D module, with IN1 and IN2 on pins 7 and 8 and EN on pin 9, which is PWM-capable on an Uno.
const uint8_t IN1 = 7;
const uint8_t IN2 = 8;
const uint8_t EN = 9; // must be a PWM-capable pin
void setup() {
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(EN, OUTPUT);
}
// speed: -255 (full reverse) to 255 (full forward), 0 = stopped
void setMotor(int speed) {
speed = constrain(speed, -255, 255);
if (speed > 0) {
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
} else if (speed < 0) {
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
} else {
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
}
analogWrite(EN, abs(speed));
}
void loop() {
setMotor(200);
delay(2000);
setMotor(0);
delay(500);
setMotor(-200);
delay(2000);
setMotor(0);
delay(500);
}In terms of the bridge, IN1 high with IN2 low closes one diagonal pair of switches (S1 and S4, if A is the IN1 side). IN1 low with IN2 high closes the other diagonal (S3 and S2). The next chapter walks through those pairs and the current paths in detail. For now, notice that the code never asks for four separate switches. The driver makes that decision.
Edge cases and common mistakes
- Treating the enable pin as optional. On many modules a jumper ties EN high. If you remove the jumper to use PWM and then wire EN to a non-PWM pin, speed control silently becomes on and off only.
- Assuming the logic pins set the motor voltage. They only select switch states. The motor's voltage comes from VM, minus the driver's drop.
- Expecting full supply voltage at the motor. A bipolar driver with a 1.5 V drop per leg of the path can turn a 6 V supply into roughly 3 V at the motor. Measure across the motor terminals, not at the supply.
- Closing both switches on one side. Keep this in mind when you work with raw MOSFETs. An integrated driver blocks it, but a discrete bridge driven from separate pins does not unless you write the protection yourself.
- Connecting the motor to the wrong side of the module. Swapping the two motor wires only reverses which direction counts as forward. It does not damage anything, so fix it in wiring or in code.
Summary
- An H-bridge is four switches in two half bridges, with the motor connected between the two midpoints.
- Tying each motor terminal to VM or ground lets one supply drive the motor in either direction.
- Real switches are bipolar transistors or MOSFETs, which differ in voltage drop and heat.
- Driver chips turn two or three logic inputs into the right switch states and block unsafe combinations.
Exercise
A driver uses MOSFETs with RDS(on) of 0.1 ohm per switch, and current flows through two switches in series. A motor draws 2 A from a 12 V supply. How much power does the bridge dissipate, and what voltage reaches the motor, ignoring the motor's own resistance changes?
Show answer
Two switches in series give 0.2 ohm. Power is I² × R = 2² × 0.2 = 0.8 W. The voltage drop is 2 A × 0.2 ohm = 0.4 V, so the motor gets about 11.6 V. A bipolar bridge dropping 1.5 V per switch would lose about 3 V and dissipate about 6 W at the same current.
Exercise
Why can a circuit with a single supply and only low-side switches not reverse a motor, and what does a four-switch bridge add?
Show answer
With only low-side switches, one motor terminal stays permanently tied to VM, so the polarity across the motor can never flip. The four-switch bridge adds a high-side switch on each side, so either terminal can be connected to VM and the other to ground, which reverses the polarity across the motor.