How Does an H-Bridge Motor Driver Work?
In this article
An H-bridge motor driver works by using four switches arranged in an H pattern to control the direction and speed of a DC motor. By turning on opposite pairs of switches, you can make the motor spin forward or backward; by switching them rapidly (PWM), you can vary the speed. This guide explains the concept step by step, shows how to wire a typical H-bridge module, and covers the mistakes that cause most failures.
What You'll Need
- A DC motor (brushed, 3–12 V typical for small projects)
- An H-bridge driver module or IC (e.g., L298N, TB6612FNG, or a discrete MOSFET H-bridge)
- A microcontroller (Arduino, ESP32, Raspberry Pi Pico, etc.)
- An external power supply for the motor, rated for its voltage and current
- Jumper wires and a breadboard or soldered connections
- Optional: a multimeter, a flyback diode (if not built into the module), and a heatsink for the driver IC
Step-by-Step
- Understand the H pattern. Imagine four switches: top-left (S1), bottom-left (S2), top-right (S3), bottom-right (S4). The motor sits between the left and right midpoints. Closing S1 and S4 connects the motor's left terminal to positive and its right terminal to ground, so current flows one way and the motor spins forward. Closing S3 and S2 reverses the connection, so the motor spins backward. Never close S1 and S2 together (or S3 and S4 together) — that creates a short circuit across the supply, called shoot-through, which can destroy the driver.
- Choose a driver that matches your motor. Check the motor's stall current, not just its free-running current. A small L298N module handles about 2 A per channel with a heatsink; a TB6612FNG handles about 1.2 A continuous per channel. Pick a driver rated above your motor's stall current, or add current limiting.
- Wire the power supplies correctly. Connect the motor power supply to the driver's VIN (or VMOT) and ground. Connect the microcontroller's ground to the same ground — a common ground is essential. If the module has a 5 V output or logic supply pin, use it only for logic-level reference, not to power the motor.
- Connect the motor. Attach the motor's two leads to the driver's OUT1 and OUT2 (or A1/A2) terminals. Polarity here only determines which direction is "forward"; you can swap the leads later if needed.
- Connect the control inputs. For a typical module, connect IN1 and IN2 to two microcontroller GPIO pins. These set the direction: IN1 high and IN2 low = forward; IN1 low and IN2 high = reverse; both low = coast (motor freewheels); both high = brake (motor terminals shorted). If the module has an ENA (enable) pin, connect it to a PWM-capable pin to control speed.
- Write the control code. Set the direction pins, then use analogWrite (or your platform's PWM function) on the enable pin. For example, to run forward at half speed: set IN1 high, IN2 low, then analogWrite(ENA, 128) on an 8-bit PWM. To reverse, swap IN1 and IN2. To stop, set both direction pins low (coast) or both high (brake).
- Test with the motor disconnected from the load. Power up and check that the motor spins in both directions and that speed changes with PWM. If the motor does not move, check the common ground and the enable pin first.
- Add flyback protection if needed. Most integrated drivers include internal flyback diodes. If you are building a discrete H-bridge from MOSFETs, add a diode across each switch to clamp the inductive spike from the motor. Without them, the transistors can fail.
- Mount and heatsink. Drivers like the L298N get hot at higher currents. Bolt the IC to a heatsink or use a module with one. Keep motor wires short and twisted to reduce electrical noise.
Common Mistakes
- No common ground. The microcontroller and motor supply must share a ground, or the control signals have no reference and the driver behaves unpredictably.
- Shoot-through. Setting both direction pins high on some drivers is safe (brake mode), but on a discrete H-bridge it can short the supply. Always check the driver's truth table.
- Powering the motor from the microcontroller's 5 V pin. Motors draw far more current than a GPIO or onboard regulator can supply; this can reset or damage the board.
- Ignoring stall current. A motor that draws 0.5 A free-running may draw 3 A when stalled. Size the driver and supply for the stall current.
- Using PWM on the direction pins instead of the enable pin. Some drivers allow it, but many do not; use the enable pin for speed control unless the datasheet says otherwise.
- Forgetting the decoupling capacitor. A small capacitor across the motor terminals reduces brush noise that can interfere with the microcontroller.
Tips
- Start with a low PWM duty cycle (around 20–30%) when testing, then increase.
- Use a multimeter to confirm voltage at the motor terminals before connecting the motor.
- Label your wires: IN1, IN2, ENA, VIN, GND, OUT1, OUT2. It saves hours later.
- If the driver has a current-sense pin, use it to detect stalls and protect the motor.
- For bidirectional control with a single PWM pin, some drivers (like the TB6612) use two direction pins plus one PWM pin; others use an IN/IN enable scheme. Read the module's pinout.
Troubleshooting
- Motor does not spin at all: Check the common ground, the enable pin (must be high or PWM), and the power supply voltage. Measure at the driver's motor output terminals.
- Motor spins only one direction: One direction pin is not receiving a signal. Check the microcontroller pin, the wire, and the code.
- Motor spins weakly or stutters: The supply cannot deliver enough current, or the PWM frequency is too low/high for the driver. Try a different supply and check the driver's recommended PWM frequency.
- Driver gets very hot: Current is too high or the heatsink is inadequate. Reduce load, add a heatsink, or use a driver with a higher current rating.
- Microcontroller resets when the motor starts: The motor is drawing current from the same supply as the logic, causing voltage dips. Use a separate motor supply and a common ground.
- Motor runs but direction is reversed: Swap the motor leads or swap the IN1/IN2 signals in code.
Frequently Asked Questions
Can I use an H-bridge to control a stepper motor?
Not directly. A stepper motor needs a dedicated stepper driver that sequences multiple coils. An H-bridge controls one coil pair; a stepper has two or more.
What is the difference between coast and brake?
Coast means the motor terminals are disconnected (both low), so the motor freewheels. Brake means the terminals are shorted (both high), which resists rotation and stops the motor faster.
Do I need a heatsink for an L298N?
Yes, for anything beyond light loads. The L298N drops voltage internally and dissipates heat; without a heatsink it can overheat and shut down or fail.
Can I power the H-bridge from the same supply as my Arduino?
Only if the supply can handle the motor's stall current and the voltage is within the Arduino's input range. In most cases, use a separate motor supply and connect the grounds together.
Why does my motor whine at low PWM values?
Low duty cycles can cause the motor to vibrate audibly. Raise the PWM frequency above the audible range (e.g., 20 kHz) if your driver supports it, or avoid very low duty cycles.