An H-bridge is a set of four switches arranged in an H around the motor. Closing one diagonal pair drives current through the motor in one direction. Closing the other diagonal pair reverses it. Driver chips such as the L293D and L298N put these switches in one package, so an Arduino can control direction and speed with a few pins.
How an H-bridge reverses the motor
The four switches sit in two legs. Each leg has a high-side switch to the supply and a low-side switch to ground. The motor connects between the two legs.
| State | Switches closed | What the motor does |
|---|---|---|
| Forward | High-side left and low-side right | Current flows one way through the motor |
| Reverse | High-side right and low-side left | Current flows the other way |
| Brake | Both low-side switches | Motor terminals are shorted together, so it slows quickly |
| Coast | All switches open | Motor spins freely and slows gradually |
Never close both switches in the same leg. That connects the supply straight to ground through the leg. This is called shoot-through, and it can destroy the driver and overheat the wiring. Driver chips are built to prevent this inside the package, but a mistake when wiring discrete switches or MOSFETs can still cause it.
A basic reversing circuit from two switches
You can demonstrate the principle with two SPDT (on-off-on) switches. Each switch connects one motor terminal to either the positive supply or to ground. Flip both switches to reverse the motor. This setup has no speed control and no brake state, so it is a teaching tool rather than a practical driver.
L293D or L298N
Each chip contains two H-bridges. That means one chip can drive two DC motors, one per bridge, or a single bipolar stepper motor, which uses both bridges.
| L293D | L298N | |
|---|---|---|
| Continuous current per channel | About 600 mA | About 2 A |
| Motor supply | Up to about 36 V | Up to about 46 V |
| Heat | Modest loads only | Needs a heat sink at higher currents |
| Flyback diodes | Built in | Check the datasheet or your module |
The L298N drops a noticeable voltage across the chip, so the motor sees less than the supply voltage. Many L298N modules also include a regulator for the logic supply, which can be jumpered on or off. Check your module’s label before you connect a logic supply.
The motor supply and the logic supply are separate. Connect the grounds together, but keep the motor’s current away from the Arduino.
Wiring to an Arduino
- IN1 and IN2 set the direction. One is high and the other is low for forward or reverse.
- EN (enable) turns the bridge on. Connect it to a PWM pin, and use
analogWriteto set the speed. - Grounds: connect the Arduino ground to the driver ground.
Arduino sketch
const int IN1 = 8;
const int IN2 = 9;
const int ENA = 10; // PWM pin for speed
void setup() {
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(ENA, OUTPUT);
}
void loop() {
// Forward at about half speed
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
analogWrite(ENA, 128);
delay(2000);
// Reverse at about half speed
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
analogWrite(ENA, 128);
delay(2000);
}
Use the pin names on your board. The L293D’s enable pins are labelled EN1,2 and EN3,4, and the L298N module labels them ENA and ENB.
Common problems
- The motor does not reverse: check the IN1 and IN2 wiring and the code that sets them.
- No speed control: the enable pin must be on a PWM pin and driven with
analogWrite. - The chip gets hot: reduce the current, add a heat sink, or move to a higher-rated driver.
- The Arduino resets when the motor starts: the motor supply is probably sharing a noisy path with the logic. Use separate supplies and add capacitors across the motor supply.
- Current limit reached: a stalled motor draws much more current than a running one. Use a fuse, or limit the current in the supply.
Going further
Driver chips handle small motors well. Larger motors usually need MOSFET H-bridges, which are built from discrete parts. Whatever the driver, the motor needs a flyback diode or a built-in equivalent. See why a DC motor needs a flyback diode. For single-direction speed control, see DC motor speed control using PWM.