L298N Dual H-Bridge DC Motor Driver

Run two DC motors forward, backward, and at any speed with a single L298N module — the workhorse H-bridge behind every small robot, conveyor demo, and remote-controlled car project.

Difficulty: Breadboard. Estimated build time: about 35 minutes. Estimated parts cost: about US$6.80. 5-line bill of materials. Compare supplier offers when available. A motor controller that lets you spin two DC motors independently in either direction at any speed you choose — without the motor noise or current draw destroying your MCU.

Wire the motor and supply

The L298N module needs TWO power inputs: a 'motor' supply (anywhere from 5 to 12 V — match it to your motor's rated voltage) on the +12V terminal, and a 5 V logic supply on the +5V terminal. Most modules can self-generate the 5 V from the motor supply via an onboard regulator if you leave the jumper on — set that jumper before plugging anything in. Ground both supplies to the GND terminal. Connect motor A across OUT1 and OUT2, motor B across OUT3 and OUT4.

Wire the control pins

Each motor channel has three control pins: ENA (enable, accepts PWM), IN1, IN2 (direction). Wire ENA to a PWM-capable GPIO, IN1 and IN2 to two regular GPIOs. To drive the motor forward: IN1 = HIGH, IN2 = LOW, ENA = PWM at desired duty cycle. Reverse: IN1 = LOW, IN2 = HIGH. Brake (both HIGH or both LOW): motor stops fast. Repeat for ENB, IN3, IN4 on motor B.

Drive both motors

Write a small loop that ramps motor A from 0 to 255 PWM forward over two seconds, holds for one second, ramps back to zero, flips direction, ramps up reverse, and so on. The motor should accelerate and decelerate smoothly. Add motor B with an offset so the two motors run at different speeds — a robot-friendly differential-drive demo. Watch the motor supply current with a multimeter if you can; a stalled motor at 12 V can spike to 1.5-2 A, which is why the L298N has built-in heat sinking.