Two-wheel robot drifts to one side: motor mismatch and fixes

Two identical-looking DC motors never run at exactly the same speed with the same PWM. The robot curves toward the slower side.

What the message means

Gear friction, supply drop and small motor differences change the speed. Open-loop PWM does not correct them.

Fix it in this order

  1. Check that both wheels are the same size and spin freely.
  2. Add a trim factor: scale the PWM for one motor until the robot runs straight, as a quick fix.
  3. Check both motors take the same supply voltage at the driver outputs.
  4. For a lasting fix use encoders and a small speed control loop for each wheel.
  5. Test on a flat floor, at the speed you will really use.

Why it happens

Two motors given the same PWM value rarely turn at the same speed, because of differences in the motors, gearboxes, wheels and driver. The robot curves toward the slower side.

A quick fix is a trim factor on one side. A better fix is feedback: read encoders and adjust each side to the same measured speed.

float TRIM_LEFT = 1.00;   // try 0.95 to 1.05
setMotors((int)(speed * TRIM_LEFT), speed);   // your function: left, right

Example sketch: change pins and values for your own wiring. It has not been bench-tested on your hardware.

If you see this, do this

You seeDo this
Drift changes with battery chargeUse feedback instead of a trim.
Always drifts the same wayMechanical or trim problem.

encoder counts, wheel speed calculator.

Last reviewed: November 2026. These are the usual causes and the order that finds them fastest. Test on your own board; clones and cables differ.

Why this happens

Two DC motors with the same PWM duty are given the same average voltage, but they do not turn at the same speed. Brushes, gearbox friction, magnet strength and supply wiring all differ a little, and a few percent of speed difference is common. Without feedback, nothing corrects it, so the robot follows a gentle arc.

The size of the arc follows from geometry. With wheel separation b and wheel speeds vL and vR, the turning radius is R = (b / 2) x (vR + vL) / (vR – vL). The smaller the difference, the larger the radius, but it never becomes straight. After driving a distance d, the heading error is about d / R radians, and the sideways error is about d squared divided by 2R.

How to confirm the cause

  • Lift the robot so the wheels are free. Run both motors at the same PWM for 10 seconds and count wheel turns or encoder ticks. The difference in counts is the speed mismatch.
  • Swap the left and right motor connections in the driver wiring and run again. If the drift flips direction, the motors or the driver channels are the cause. If it stays on the same side, look at the mechanics, such as friction or a caster.
  • Measure the voltage at each motor’s terminals while running. A difference points to wiring or driver channels.
  • Spin each wheel by hand with the power off. One wheel that is stiffer than the other shows a binding axle or gearbox.
  • Check the wheel diameters with a ruler or calipers. A worn or different tyre changes the distance per turn.

Worked example

What a small mismatch does, worked out with example numbers:

Wheel separation b = 0.15 m
Left speed = 0.98 x right speed (2 percent slower)
R = (b/2) x (vR + vL) / (vR - vL) = 0.075 x 1.98 / 0.02 = 7.4 m
Drive d = 2 m: heading change = 2 / 7.4 = 0.27 rad = about 15 degrees
Sideways offset = d^2 / (2R) = 4 / 14.8 = about 0.27 m

Common mistakes

  • Calibrating the trim on a fresh battery and expecting it to hold when the battery is half empty.
  • Running one motor at full PWM already, so the trim cannot raise it any further.
  • Ignoring the caster wheel, which can drag to one side.
  • Mixing tyres of different wear or size.
  • Testing on a rug or a sloped floor and tuning to the floor, not the robot.

If this did not fix it

  • A caster wheel that catches or swivels slowly can pull the robot to one side.
  • Different wire lengths or loose connectors on the two motors change the voltage each motor gets.
  • Wheel slip on a smooth floor can look like drift, particularly during acceleration.