DC motors and H-bridge drivers: how a robot moves
A DC motor is the simplest way to move a robot: give it voltage and it spins, reverse the voltage and it spins the other way. But you cannot wire it straight to an Arduino or Pi pin, those pins deliver tiny currents and a motor needs a lot.
The H-bridge
An H-bridge is a small circuit (often a ready-made module like an L298N) that sits between your controller and the motor. It does two jobs:
- Direction: two control pins decide which way current flows, so the motor spins forward or backward.
- Power: it draws current from a separate battery, not from your controller.
Typical wiring per motor: two direction pins plus one PWM pin for speed.
IN1, IN2 -> direction (forward / reverse / stop)
ENA (PWM) -> speed (0..255)
Speed and direction together
- Both direction pins the same: motor stops (brake).
- One high, one low: spins one way. Swap them: spins the other way.
- The PWM value on the enable pin sets how fast.
Powering it right
The golden rule: the motor battery is separate from the controller supply, and all grounds are connected together. Motors create electrical noise and current spikes that can crash or damage a logic board if they share the same power line.
Two motors make a robot
Put a motor on each side and you have differential drive: both forward to go straight, one faster to turn, opposite directions to spin in place. That simple setup is behind most small robots. Next, meet the precise cousin of the motor, the servo.