Zbotic Logo Zbotic Logo
  • Home
  • Shop
  • Sale
  • 3D Print Service
  • PCB Service
  • B2B
  • Blogs
  • Contact Us
0 0

View Wishlist Add all to cart

0 0
0 Shopping Cart
Shopping cart (0)
Subtotal: ₹0.00

View cartCheckout

  • Shop
  • About Us
  • Contact Us
  • Reseller
  • Blogs
020 69134444
1800 209 0998
[email protected]
Help Desk
Facebook Twitter Instagram Linkedin YouTube
Zbotic Logo Zbotic Logo
0 0

View Wishlist Add all to cart

0 0
0 Shopping Cart
Shopping cart (0)
Subtotal: ₹0.00

View cartCheckout

All departments
  • 3D Print Service
  • 3D Printer
  • Batteries & Chargers
  • Development Boards
  • Drone Parts
  • EBike parts
  • Sensor Modules
  • Electronic Components
  • Electronic Modules
  • IoT and Wireless
  • Mechanical Parts and Workbench Tools
  • Motors & Drivers & Pumps & Actuators
  • DIY and Robot Kits
  • Show more
  • Home
  • Shop
  • Sale
  • 3D Print Service
  • PCB Service
  • B2B
  • Blogs
  • Contact Us
Return to previous page
Home Robotics & DIY

Robot Speed Control: Motor Driver Tuning for Straight Motion

Robot Speed Control: Motor Driver Tuning for Straight Motion

March 11, 2026 /Posted byJayesh Jain / 0

One of the most frustrating problems beginners face after assembling their first robot is that it doesn’t travel in a straight line. Robot speed control and motor driver tuning is the key to solving this. Even two identical DC motors from the same batch have slightly different internal resistances, back-EMF characteristics, and friction profiles. Without proper calibration, your robot will curve left or right even when you command equal speed to both wheels. This tutorial explains exactly how to diagnose, tune, and fix this problem using PWM control, feedback techniques, and PID correction.

Table of Contents

  1. Why Robots Drift: Root Cause Analysis
  2. Motor Driver Options and Their Role in Speed Control
  3. PWM Basics for DC Motor Speed Control
  4. Manual Calibration Method
  5. Using Encoders for Closed-Loop Control
  6. PID Tuning for Straight Motion
  7. Special Case: Mecanum Wheel Speed Balancing
  8. FAQ

Why Robots Drift: Root Cause Analysis

Before tuning, you need to understand why drift happens in the first place. The main causes are:

  • Motor mismatch: Two motors at the same PWM duty cycle run at different RPMs due to manufacturing tolerances (typically 5–15% variation).
  • Friction differences: One wheel may have more bearing friction, load imbalance, or different tyre grip.
  • Motor driver deadband: L298N drivers have a ~1.4V drop per transistor (total 2.8V). At low PWM values, one channel may be in the driver’s dead zone while the other is active.
  • Battery voltage sag: As the battery discharges, voltage drops unevenly affect the two motor channels differently.
  • Structural asymmetry: If your chassis is not perfectly balanced or the centre of gravity is off-centre, one wheel bears more weight and experiences more drag.

Motor Driver Options and Their Role in Speed Control

Your choice of motor driver significantly affects how well you can tune speed. Here are the most common options:

Driver Max Current Voltage Drop PWM Freq
L298N 2A/channel 2.8V (high) Up to 25kHz
L293D 600mA/ch 3V+ (very high) Up to 5kHz
TB6612FNG 1.2A/ch 0.5V (low) Up to 100kHz
DRV8833 1.5A/ch 0.3V (very low) Up to 100kHz

For precision speed control, TB6612FNG or DRV8833 are far superior to the L298N because of their MOSFET-based design with minimal voltage drop. However, L298N is the most commonly used in starter kits and can still be tuned effectively.

PWM Basics for DC Motor Speed Control

PWM (Pulse Width Modulation) controls motor speed by rapidly switching power on and off. The duty cycle — percentage of time the signal is HIGH — determines effective voltage:

  • 100% duty cycle = full voltage to motor = maximum speed
  • 50% duty cycle = ~half voltage = approximately half speed
  • 25% duty cycle = very slow, but may stall under load

On Arduino, analogWrite(pin, value) sets duty cycle from 0–255. So analogWrite(ENA, 128) is ~50% duty cycle. The default Arduino PWM frequency is 490Hz on most pins (980Hz on pins 5 and 6). For motor control, 490Hz creates audible whining — you can change the Timer prescaler to use higher frequencies if needed.

Key insight: Never run motors below their minimum effective PWM value (usually 60–80 for L298N) — below this threshold the motor won’t move but will hum and heat the driver.

Manual Calibration Method

If you don’t have encoders, use this simple manual method:

  1. Set both motors to PWM 200 out of 255.
  2. Run the robot on a flat surface for exactly 1 metre. Mark start and end points.
  3. Measure lateral drift (how far it veered left or right).
  4. If it drifts right, reduce right motor PWM by 5. If left, reduce left motor PWM by 5.
  5. Repeat until the robot travels straight within ±2cm over 2 metres.

Store calibration offsets as constants in your code:

const int BASE_SPEED = 200;
const int LEFT_TRIM = 0;   // adjust these
const int RIGHT_TRIM = -8; // negative = reduce speed

void moveForward() {
  analogWrite(ENA, BASE_SPEED + LEFT_TRIM);
  analogWrite(ENB, BASE_SPEED + RIGHT_TRIM);
  // direction pins...
}

Using Encoders for Closed-Loop Control

Manual calibration breaks down when battery voltage changes or the robot moves on different surfaces. Wheel encoders provide real-time speed feedback for true closed-loop control. Two types are common:

  • Hall effect encoders: Magnetic. More accurate, works at low speed, immune to dust. Built into some geared motors.
  • Optical encoders: A slotted disk interrupts an IR beam. Simple and cheap. Used with encoder disks clipped onto wheels.

With encoder counts, you can calculate actual RPM:

// Interrupt-driven encoder counting
volatile long leftCount = 0, rightCount = 0;

void leftISR() { leftCount++; }
void rightISR() { rightCount++; }

void setup() {
  attachInterrupt(digitalPinToInterrupt(2), leftISR, RISING);
  attachInterrupt(digitalPinToInterrupt(3), rightISR, RISING);
}

Compare left and right counts every 50ms. If they diverge, adjust the lagging motor’s PWM upward.

PID Tuning for Straight Motion

For the smoothest results, implement a PID controller on the speed error between left and right wheels:

float Kp = 1.2, Ki = 0.01, Kd = 0.5;
float error, prevError = 0, integral = 0;

void loop() {
  // Reset counts every 50ms
  long L = leftCount; long R = rightCount;
  leftCount = 0; rightCount = 0;

  error = L - R; // positive = left faster
  integral += error;
  float derivative = error - prevError;
  float correction = Kp*error + Ki*integral + Kd*derivative;
  prevError = error;

  int leftPWM  = constrain(BASE_SPEED - correction, 0, 255);
  int rightPWM = constrain(BASE_SPEED + correction, 0, 255);
  analogWrite(ENA, leftPWM);
  analogWrite(ENB, rightPWM);
  delay(50);
}

Tuning guide: Start with Kp only (Ki=0, Kd=0). Increase Kp until the robot oscillates, then halve it. Add small Kd to dampen oscillation. Add tiny Ki only if there’s persistent steady-state error. Most differential drive robots need very small Ki values (0.001–0.05).

Special Case: Mecanum Wheel Speed Balancing

Mecanum wheel robots require all four wheels to run at precisely matched speeds. Speed imbalance causes unexpected lateral drift rather than just curved forward motion. For mecanum platforms:

  • Use encoders on all four wheels (or at minimum, diagonal pairs).
  • Run separate PID loops per motor.
  • Calibrate at the exact operating voltage — mecanum drift is highly sensitive to voltage variations.
  • Test all four motion modes: forward, strafe, rotate, diagonal.
60MM-K Mecanum Wheel Compatible with 6.7mm Coupling Black

60MM-K Mecanum Wheel (Pack of 4) – Black

A complete set of 60mm mecanum wheels for omnidirectional robot movement. Requires precise speed matching across all four motors for smooth strafe and diagonal motion.

View on Zbotic

80mm-A Mecanum Wheel Black

80mm-A Mecanum Wheel (Pack of 4) – Black

Larger 80mm mecanum wheels for heavier robot platforms. Provides better load capacity while maintaining omnidirectional capability. Compatible with 6.7mm motor shaft couplings.

View on Zbotic

4mm Hex coupling for Robot Smart Car Wheel

4mm Hex Coupling for Robot Smart Car Wheel (30mm)

Metal hex couplings for attaching wheels to DC motor shafts. Essential for mecanum and standard wheel builds to ensure zero slip between motor shaft and wheel hub.

View on Zbotic

4 Wheels Car Chassis Acrylic Frame

4 Wheels Car Chassis Acrylic Frame

A well-proportioned 4WD acrylic chassis for building a speed-tuned robot. Balanced weight distribution helps reduce the structural asymmetry that causes drift.

View on Zbotic

Frequently Asked Questions

Why does my robot drift more at lower speeds?
At low PWM values, you’re closer to the motor’s deadband — tiny differences in motor resistance have a proportionally larger effect. This is why L298N robots drift more at slow speeds. Use TB6612FNG for better low-speed control.
Should I use hardware or software PWM?
Always use hardware PWM (Arduino’s analogWrite on PWM pins). Software PWM interrupts the main loop and causes timing jitter that makes speed control unreliable.
How do I know if I need PID or if manual trim is enough?
If your robot runs on a single surface type at a fixed speed, manual trim often suffices. If speed varies, surface changes, or battery depletes during operation, use PID with encoders.
My L298N gets very hot — is this normal?
The L298N dissipates 2.8V × motor current as heat. At 1A per channel, that’s 2.8W of heat — significant. Attach the included heatsink. If it gets uncomfortably hot to touch, your motor current is too high or you need to switch to a MOSFET driver.
Can I tune speed control without encoders using IMU?
Yes — an MPU6050 gyroscope can measure yaw rotation. If the robot turns left, increase right motor speed. This is less accurate than encoders but works without modifying the wheels.

Build a Robot That Truly Travels Straight

Proper robot speed control and motor driver tuning transforms a wobbly prototype into a reliable machine. Whether you use manual trim for a simple 2WD robot or full PID with encoders for a competition bot, the principles here apply universally. Find all the motor drivers, wheels, couplings, and chassis components you need at Zbotic — shipped fast across India.

Shop Motor Control Components at Zbotic

Tags: DC motor robot arduino, L298N PWM calibration, motor driver tuning, robot speed control, robot straight line motion
Share Post
  • Facebook
  • Linkedin
  • Whatsapp
Autonomous Delivery Bot: ROS N...
blog autonomous delivery bot ros navigation lidar mapping diy 597554
blog esp32 mdns access devices by name instead of ip address 597563
ESP32 mDNS: Access Devices by ...

Related posts

Svg%3E
Read more

Caterpillar Track Robot: Tank-Drive Build for All Terrain

April 1, 2026 0
When wheels lose grip on sand, gravel, grass, or loose surfaces, caterpillar tracks keep moving. A tank-track robot distributes its... Continue reading
Svg%3E
Read more

RC Car to Robot: Convert a Toy Car into an Autonomous Robot

April 1, 2026 0
That old RC toy car gathering dust can be transformed into an Arduino-controlled autonomous robot with just a few electronic... Continue reading
Svg%3E
Read more

Robotic Arm Kit India: Best Options for Students and Hobbyists

April 1, 2026 0
If you are a student or hobbyist looking to get into robotics, a robotic arm kit is one of the... Continue reading
Svg%3E
Read more

Sumo Robot: Competition Build Guide India

April 1, 2026 0
Sumo robot competitions are among the most exciting events in Indian robotics, pitting small autonomous robots against each other in... Continue reading
Svg%3E
Read more

Robot Arm Build: 6-DOF Servo Arm with Arduino Control

April 1, 2026 0
Building a 6-DOF robot arm with servo motors and Arduino is one of the most rewarding robotics projects you can... Continue reading

Add comment Cancel reply

Your email address will not be published. Required fields are marked

Facebook Twitter Instagram Pinterest Linkedin Youtube

Get the latest deals and more.

Download on Google Play Download on the App Store

Call us: 020 69134444 / 1800 209 0998

Monday - Saturday 09:30 AM - 06:00 PM
For Technical Supports Email: [email protected]
For Sales / Enquiries Email: [email protected]

  • My Account

    • Cart

    • Wishlist

    • Checkout

    • My Orders

    • Track Order

    • My Account

  • Information

    • FAQs

    • Blogs

    • Career

    • About Us

    • Contact Us

    • Payment Options

  • Policies

    • Privacy Policy

    • Terms & Conditions

    • GST Input Tax Credit

    • Shipping Return Policy

    • E-Waste Collection Points

    • Our Sitemap

© Zbotic.in is registered trademark of Moxie Supply Pvt Ltd – All Rights Reserved
Login
Use Phone Number
Use Email Address
Not a member yet? Register Now
Reset Password
Use Phone Number
Use Email Address
Register
Already a member? Login Now