Mecanum Wheel Robot Car Build: Omni-Directional Drive

Mecanum wheel robot car chassis with four omni wheels

Mecanum Wheel Robot Car Build: Omni-Directional Drive

Build a mecanum wheel robot car that drives forward, sideways, and diagonally without turning. Each wheel carries rollers set at 45 degrees, and the four wheels spin in matched patterns to strafe. The build uses two L298N drivers, one per wheel pair, because one L298N drives only two motors and a mecanum car has four.

Quick facts

Item Value
Chassis Mecanum 4WD chassis, aluminum alloy, 0.20 feet omni wheels
Drivers 2 x L298N, one per wheel pair
Motors 4 x TT gear motors, 3 to 6 V
Controller ESP32 DevKit V1, 3.3 V logic
Roller angle 45 degrees on each wheel
Moves Forward, back, strafe left, strafe right, rotate, diagonal

Mecanum wheel robot car: how does a wheel move sideways?

A mecanum wheel has small rollers around its rim, each set at 45 degrees to the wheel axle. When the wheel spins, the roller pushes the car partly forward and partly sideways. One wheel alone would slide diagonally, but four wheels in the right pattern cancel the unwanted parts.

For a strafe left, the front left and rear right wheels spin one way while the front right and rear left spin the other way. The forward parts cancel and the sideways parts add. The car slides left without turning. Reverse the pattern and it strafes right. That is the move a normal car cannot make.

Wheel orientation matters. The rollers on the front left and rear right wheels must angle one way, and the rollers on the front right and rear left must angle the other way, forming an X pattern when viewed from above. If one wheel is fitted backward, the car will crab and spin instead of strafing. Check the X before you wire anything.

Why does this build need two L298N drivers?

One L298N drives two DC motors. A mecanum car has four motors, so it needs two L298N modules. Each module drives one diagonal pair: the first drives the front left and rear right wheels, and the second drives the front right and rear left wheels. That pairing matches the strafe pattern and keeps the wiring tidy. Buy the 4WD Kit variant of the chassis kit: it ships with 4 TT gear motors and one L298N, so buy one more L298N for the second pair. The Plate Set variants ship with plates and wheels only, no motors or electronics. The 4WD Kit also includes a UNO R3 board and sensor shield; this build uses an ESP32 DevKit V1 in its place.

Each L298N needs its own enable and direction pins, so the build uses 12 control pins on the ESP32. The ESP32 DevKit V1 has enough GPIO pins for that, but a small board such as a SuperMini would not. Check the pinout post for your exact board before you substitute it.

Both L298N modules share one motor battery. Join the battery positive to both 12 V terminals and the battery negative to both grounds and to the ESP32 ground. Keep the 5 V jumper on at 6 V, and remove it above 12 V, on both modules.

How does the drive mix work?

The drive mix takes three inputs: forward speed, strafe speed, and rotation speed. Each wheel speed is a sum of those three with signs that depend on the wheel position. Front left equals forward plus strafe plus rotation. Front right equals forward minus strafe minus rotation. Rear left equals forward minus strafe plus rotation. Rear right equals forward plus strafe minus rotation.

The sketch below implements that mix for serial control. Type f for forward, s for strafe left, d for strafe right, l to rotate left, r to rotate right, and x to stop. Each key sets the four wheel speeds from the mix, clamps them to -255 to 255, and writes them to the two L298N modules.

Test the mix with the car lifted. Strafe left should spin the front left and rear right wheels one way and the other two the opposite way. If one wheel spins the wrong way, swap its two motor wires at its L298N output. Do not fix wheel direction in code, because the wiring is the fault.

What are the limits of a mecanum car?

Mecanum wheels slip more than normal wheels, because the rollers are always partly sliding. The car will not climb as well, will not push as hard, and will drift on smooth floors. It also draws more current, because two wheels fight each other in every strafe. Expect shorter battery life than a normal 4WD car on the same pack.

The rollers also wear faster than a solid tire, and they pick up grit. Keep the floor clean and the rollers free. A stuck roller turns a mecanum wheel into a bad normal wheel, and the car will crab instead of strafing.

For all that, the strafe is worth it on a bench or a small course. A mecanum car can slide sideways into a gap a normal car cannot reach, and it can rotate in place without a turning circle. That is why warehouse robots and camera dollies use the same wheel.

Wiring

Wire the build with the power off. Check every connection in the table before you connect any battery or USB cable.

From To Notes
Battery box positive Both L298N 12 V terminals Motor supply, 6 V from 4 AA cells
Battery box negative Both L298N GND and ESP32 GND Common ground for both drivers and the logic
L298N A OUT1, OUT2 Front left TT motor First module, left channel
L298N A OUT3, OUT4 Rear right TT motor First module, right channel
L298N B OUT1, OUT2 Front right TT motor Second module, left channel
L298N B OUT3, OUT4 Rear left TT motor Second module, right channel
ESP32 GPIO 25, 27, 14 L298N A ENA, IN1, IN2 Front left motor: PWM, direction A, direction B
ESP32 GPIO 26, 12, 13 L298N A ENB, IN3, IN4 Rear right motor: PWM, direction A, direction B; GPIO 12 is a strapping pin, keep low at boot
ESP32 GPIO 32, 33, 15 L298N B ENA, IN1, IN2 Front right motor: PWM, direction A, direction B
ESP32 GPIO 18, 19, 21 L298N B ENB, IN3, IN4 Rear left motor: PWM, direction A, direction B; GPIO 21 is also I2C SDA, so do not add I2C parts to this build
Both L298N 5 V pins Leave unconnected Jumpers fitted at 6 V; do not feed 5 V in as well
USB 5 V ESP32 USB port Logic supply only; motor current never passes through USB

Power budget

Four TT motors draw more than two. At full load the four motors together draw about 2 to 4 A from the 6 V pack, split across two L298N modules at about 1 to 2 A per module. Each L298N drops about 2 V, so each motor sees about 4 V. The heatsinks on both modules will get warm, so give them airflow.

The ESP32 runs from USB 5 V and draws about 80 to 160 mA. Each L298N logic side draws only a few milliamps from its onboard regulator. The motor battery and the logic supply share only a ground wire. Never power the motors from the ESP32 5 V pin.

A 4 AA alkaline pack sags under a 4 A load, so the car will slow during a strafe. A 5-cell NiMH pack (6 V) holds voltage better than alkalines under load. Do not use a 2-cell lithium pack here: 7.4 V nominal is above the TT motor 3 to 6 V rating. Size the pack for the stall total, not the cruise current.

Build steps

  1. Assemble the mecanum chassis. Fit the four wheels in the X roller pattern: front left and rear right angle one way, front right and rear left the other way.
  2. Mount the two L298N modules and the ESP32 on the top plate. Label the modules A and B before you wire them.
  3. Wire the motors to the L298N outputs from the wiring table. Wire both modules to the same battery and to the ESP32 ground.
  4. Remove all four enable jumpers. Wire the 12 control pins from the wiring table.
  5. Upload the sketch below to the ESP32 DevKit V1. Lift the car off the floor for the first test.
  6. Type f, s, d, l, and r in the serial monitor and confirm each wheel spins the right way for each move.
  7. Set the car on the floor and strafe left and right. If it crabs instead of strafing, one wheel is fitted backward or wired in reverse.

Code

Libraries: none beyond the ESP32 Arduino core. Board: ESP32 DevKit V1. Control from the serial monitor: f forward, b back, s strafe left, d strafe right, l rotate left, r rotate right, x stop.

// Mecanum wheel robot car: 4 motors, 2 x L298N, ESP32
// Board: ESP32 DevKit V1. No extra libraries needed.
// Module A drives front-left (FL) and rear-right (RR).
// Module B drives front-right (FR) and rear-left (RL).
struct MotorPins { int pwm, inA, inB; };
MotorPins FL = {25, 27, 14};  // Module A, channel 1
MotorPins RR = {26, 12, 13};  // Module A, channel 2
MotorPins FR = {32, 33, 15};  // Module B, channel 1
MotorPins RL = {18, 19, 21};  // Module B, channel 2

const int SPEED = 200;  // 0 to 255; TT motors stall below about 80

void driveMotor(MotorPins m, int speed) {
  if (speed >= 0) {
    digitalWrite(m.inA, HIGH);
    digitalWrite(m.inB, LOW);
    analogWrite(m.pwm, speed);
  } else {
    digitalWrite(m.inA, LOW);
    digitalWrite(m.inB, HIGH);
    analogWrite(m.pwm, -speed);
  }
}

void stopAll() {
  driveMotor(FL, 0); driveMotor(FR, 0);
  driveMotor(RL, 0); driveMotor(RR, 0);
}

// Mix: forward, strafe (right is positive), rotation (right is positive).
void mix(int fwd, int strafe, int rot) {
  int fl = constrain(fwd + strafe + rot, -255, 255);
  int fr = constrain(fwd - strafe - rot, -255, 255);
  int rl = constrain(fwd - strafe + rot, -255, 255);
  int rr = constrain(fwd + strafe - rot, -255, 255);
  driveMotor(FL, fl); driveMotor(FR, fr);
  driveMotor(RL, rl); driveMotor(RR, rr);
}

void setup() {
  Serial.begin(115200);
  MotorPins all[4] = {FL, FR, RL, RR};
  for (int i = 0; i < 4; i++) {
    pinMode(all[i].pwm, OUTPUT);
    pinMode(all[i].inA, OUTPUT);
    pinMode(all[i].inB, OUTPUT);
  }
  stopAll();
  Serial.println("Keys: f forward, b back, s strafe left, d strafe right,");
  Serial.println("l rotate left, r rotate right, x stop.");
}

void loop() {
  if (Serial.available() > 0) {
    char c = Serial.read();
    if (c == 'f') mix(SPEED, 0, 0);
    else if (c == 'b') mix(-SPEED, 0, 0);
    else if (c == 's') mix(0, -SPEED, 0);  // Strafe left
    else if (c == 'd') mix(0, SPEED, 0);   // Strafe right
    else if (c == 'l') mix(0, 0, -SPEED);  // Rotate left
    else if (c == 'r') mix(0, 0, SPEED);   // Rotate right
    else if (c == 'x') stopAll();
  }
}

Test and tune it

Lift the car and type s for strafe left. The front left and rear right wheels should spin one way, and the front right and rear left the opposite way. If one wheel is wrong, swap its two motor wires at its L298N output.

Set the car on a hard floor and strafe left 1 foot. The car should slide sideways without turning. If it rotates while strafing, one wheel is fitted backward. Check the X roller pattern from above.

Drive forward 3 feet and mark the end point. Then strafe back to the start. A mecanum car drifts more than a normal car, so expect about 0.25 feet of error. That drift is normal roller slip, not a code fault.

FAQ

Why does my mecanum car need two L298N drivers?

One L298N drives two motors, and a mecanum car has four. Two modules drive one diagonal pair each, which matches the strafe pattern and keeps the wiring tidy.

Why does my mecanum car crab instead of strafing?

One wheel is fitted backward or wired in reverse. Check the X roller pattern from above, then check that each wheel spins the right way for a strafe while the car is lifted.

Why does the car drift sideways when driving forward?

Mecanum rollers always slip a little, and uneven floors make it worse. Small drift is normal. Large drift means one wheel is slower, usually from a loose motor wire or a low battery.

Can I use one driver board with four channels instead?

Yes, if it supplies four independent channels at the motor current. Two L298N modules are the stocked route in this build. A single four-channel MOSFET board is a later upgrade, not a first build change.

How fast can a mecanum car strafe?

Slower than it drives forward, because two wheels fight each other in every strafe and the rollers slip. Keep strafe speed at or below forward speed, and expect shorter battery life than a normal 4WD car.

Parts used

Build it with the Mecanum Wheel 4WD Robot Car Chassis Kit, Aluminum Alloy, 60mm Omni Wheels in the 4WD Kit variant (Single or Double Layer) and one more L298N Dual H-Bridge Motor Driver Module for Arduino (the kit already includes one L298N; one L298N drives two motors, so a four-motor car needs two) and the ESP32 DevKit V1 Development Board, 30-Pin WROOM-32 as the controller. The two-motor version is L298N Robot Car: Wire and Drive Two DC Motors, and the wireless version is ESP-NOW Joystick Robot Car: Two ESP32 Boards, No Router. For the driver comparison, see L298N vs TB6612 vs DRV8833: Which Motor Driver for Your Robot.

Sources

Last updated: 2026-11-21. Search volume: not verified. Product links use the store short link form with the product ID; confirm the product slug at publish time.

Bluetooth Robot Car with ESP32 BLE and a Phone

Phone showing a BLE control app next to an ESP32 robot car

Bluetooth Robot Car with ESP32 BLE and a Phone

Control this Bluetooth robot car from your phone with the ESP32 native Bluetooth Low Energy radio. No HC-05 or HC-06 module is needed, because the ESP32 DevKit V1 already has BLE built in. The car runs a BLE server with one writable characteristic, the phone writes drive commands to it, and the car stops by itself when the phone disconnects.

Quick facts

Item Value
Radio ESP32 native BLE 4.2, no extra module
Control app nRF Connect or any BLE scanner app, free
Service One custom service, one writable drive characteristic
Commands Single letters: F, B, L, R, S, plus speed digits 0 to 9
Driver L298N, 2 A per channel
Failsafe Car stops on BLE disconnect

Why use ESP32 native BLE instead of a Bluetooth module?

The ESP32 DevKit V1 has a Bluetooth radio on the chip. It supports Bluetooth Classic and Bluetooth Low Energy 4.2. A separate HC-05 module adds a second radio, a second serial port, and a second power draw for no benefit. This build uses the radio that is already on the board.

BLE is not a wireless serial port. It is a tree of named values. The car publishes a service with a characteristic, and the phone writes values to that characteristic. That sounds more complex than serial, but it gives you connection handling for free. The ESP32 knows when the phone connects and when it drops, and the sketch uses that event as the failsafe.

No HC-05 or HC-06 module is stocked for this build, so the design does not spec one. The phone app is a generic BLE scanner, not a custom app. That keeps the build to two parts: the car and the phone you already own.

Bluetooth robot car: how does BLE control work?

The car runs a BLE server. The server holds one service, identified by a UUID, and one characteristic inside it, identified by a second UUID. The characteristic accepts writes and sends notifications. The phone scans, finds the car by its advertised name, connects, and writes a short string to the characteristic.

The string is a drive command. F drives forward, B reverses, L turns left, R turns right, and S stops. A digit after the letter sets the speed from 0 to 9, so F8 means forward at speed 8. The sketch parses the letter and the digit, then drives the L298N the same way the wired car build does. Commands are two characters, far under the default 20-byte BLE payload, so no MTU change is needed.

The UUIDs in the code are examples from the standard BLE tutorial set. Generate your own UUIDs for a finished project, because reused UUIDs can confuse scanner apps when two devices advertise the same service. A free UUID generator online makes a fresh pair in seconds.

How do you drive it from a phone?

Install nRF Connect, a free BLE scanner app, on your phone. Power the car, open the app, and scan. The car advertises as ESP32-Robot-Car. Tap Connect, then open the service and the drive characteristic. Write F8 as text or bytes to drive forward at speed 8, and write S to stop.

nRF Connect is a test tool, not a joystick. Each command is a manual write, so the car holds the last command until you write a new one. That is fine for testing, but it is not smooth driving. A proper control app with buttons or a joystick sends commands continuously, and any app that writes to a BLE characteristic will work with this sketch.

Keep the phone within a few meters of the car for the first test. BLE range in open air is tens of meters, but walls and the metal chassis cut it. If commands lag, move closer before you blame the code.

What happens when the phone disconnects?

The sketch registers server callbacks for connect and disconnect. On disconnect it sets a flag, stops both motors, and restarts advertising so the phone can reconnect. That is the failsafe. A car that kept its last command after the phone died would drive until it hit a wall.

Test the failsafe on purpose. Drive forward, then switch the phone Bluetooth off or walk out of range. The car should stop within a second. If it keeps driving, the disconnect callback is not running, so check that the callbacks are set before the service starts.

The sketch also stops the car if no command arrives for 2 seconds while connected. That covers the case where the app is open but stops sending. Both timers together mean the car never runs away from a dead link.

Wiring

Wire the build with the power off. Check every connection in the table before you connect any battery or USB cable.

From To Notes
Battery box positive L298N 12 V terminal Motor supply, 6 V from 4 AA cells
Battery box negative L298N GND and ESP32 GND Common ground is required
L298N OUT1, OUT2 Left TT motor Swap these two wires to fix a reversed wheel
L298N OUT3, OUT4 Right TT motor Swap these two wires to fix a reversed wheel
ESP32 GPIO 25 L298N ENA Remove the ENA jumper; PWM speed, left motor
ESP32 GPIO 27 L298N IN1 Left motor direction A
ESP32 GPIO 14 L298N IN2 Left motor direction B
ESP32 GPIO 26 L298N ENB Remove the ENB jumper; PWM speed, right motor
ESP32 GPIO 12 L298N IN3 Right motor direction A; keep low at boot
ESP32 GPIO 13 L298N IN4 Right motor direction B
USB 5 V or battery 5 V ESP32 USB port Logic supply only; motor current never passes through USB

Power budget

The motors run from 4 AA cells at about 6 V into the L298N, which drops about 2 V, so each TT motor sees about 4 V. Two TT motors draw about 1 to 2 A together at full load. The ESP32 runs from USB 5 V or a separate 5 V supply and draws about 80 to 160 mA with BLE advertising and connected.

BLE uses less power than Wi-Fi, but the car still needs its motors on a separate supply. Never power the motors from the ESP32 5 V pin. The L298N logic draws only a few milliamps from its onboard regulator when the 5 V jumper is fitted at 6 V.

For outdoor driving, a USB power bank powers the ESP32 while the AA box powers the motors. Keep both supplies separate except for the shared ground between the battery negative, the L298N ground, and the ESP32 ground.

Build steps

  1. Assemble the chassis kit, fit the TT motors and wheels, and mount the L298N and the ESP32 on the top plate.
  2. Wire the L298N and the motors from the wiring table. Leave the 5 V jumper on for a 6 V pack.
  3. Remove the ENA and ENB jumpers. Wire the six control pins and join the battery negative to the ESP32 ground.
  4. Upload the sketch below to the ESP32 DevKit V1. No extra library is needed, because BLE ships with the core.
  5. Install nRF Connect on your phone. Power the car and scan for ESP32-Robot-Car.
  6. Connect, open the drive characteristic, and write S to confirm the link. Then write F5 and confirm both wheels spin forward.
  7. Lift the car first, then set it on the floor. Test the disconnect failsafe by switching the phone Bluetooth off while driving.

Code

Libraries: none beyond the ESP32 Arduino core (BLE ships with the core). Board: ESP32 DevKit V1. The sketch uses the core 4.0.0 BLE API (BLE.h handles, BLEProperty/BLEPermission) and will not compile on core 2.x/3.x, whose BLEDevice pointer API was removed in 4.0. The UUIDs below are the standard tutorial pair; generate your own for a finished project.

// Bluetooth robot car: ESP32 native BLE server + L298N
// Board: ESP32 DevKit V1. Library: BLE (ships with the core).
// Requires Arduino ESP32 core 4.0.0 or later (ESP-IDF 6.1.1).
// The core 2.x/3.x BLEDevice pointer API does not compile on 4.0.
#include 

static const BLEUUID SERVICE_UUID("4fafc201-1fb5-459e-8fcc-c5c9c331914b");
static const BLEUUID CHARACTERISTIC_UUID("beb5483e-36e1-4688-b7f5-ea07361b26a8");

const int ENA = 25;  // Left motor PWM (remove the ENA jumper)
const int IN1 = 27;
const int IN2 = 14;
const int ENB = 26;  // Right motor PWM (remove the ENB jumper)
const int IN3 = 12;
const int IN4 = 13;

bool deviceConnected = false;
unsigned long lastCommandMs = 0;
const unsigned long COMMAND_TIMEOUT_MS = 2000;  // Stop if silent for 2 s

void driveMotor(int pwmPin, int inA, int inB, int speed) {
  if (speed >= 0) {
    digitalWrite(inA, HIGH);
    digitalWrite(inB, LOW);
    analogWrite(pwmPin, speed);
  } else {
    digitalWrite(inA, LOW);
    digitalWrite(inB, HIGH);
    analogWrite(pwmPin, -speed);
  }
}

void drive(int left, int right) {
  driveMotor(ENA, IN1, IN2, left);
  driveMotor(ENB, IN3, IN4, right);
}

void stopCar() {
  analogWrite(ENA, 0);
  analogWrite(ENB, 0);
}

// Command format: letter plus speed digit 0 to 9.
// F8 = forward speed 8, L5 = left speed 5, S = stop.
void handleCommand(String cmd) {
  if (cmd.length() < 1) return;
  char dir = cmd.charAt(0);
  int level = 5;  // Default speed level
  if (cmd.length() > 1 && isDigit(cmd.charAt(1))) {
    level = cmd.charAt(1) - '0';
  }
  int speed = map(level, 0, 9, 0, 255);
  lastCommandMs = millis();
  if (dir == 'F') drive(speed, speed);
  else if (dir == 'B') drive(-speed, -speed);
  else if (dir == 'L') drive(-speed, speed);
  else if (dir == 'R') drive(speed, -speed);
  else if (dir == 'S') stopCar();
}

void setup() {
  Serial.begin(115200);
  pinMode(ENA, OUTPUT); pinMode(IN1, OUTPUT); pinMode(IN2, OUTPUT);
  pinMode(ENB, OUTPUT); pinMode(IN3, OUTPUT); pinMode(IN4, OUTPUT);
  stopCar();
  BLE.begin("ESP32-Robot-Car");
  BLEServer server = BLE.createServer();
  server.onConnect([](BLEServer &s, const BLEConnInfo &conn) {
    deviceConnected = true;
    lastCommandMs = millis();
  });
  server.onDisconnect([](BLEServer &s, const BLEConnInfo &conn, uint8_t reason) {
    deviceConnected = false;
    stopCar();  // Failsafe: halt on disconnect
  });
  server.advertiseOnDisconnect(true);
  BLEService svc = server.createService(SERVICE_UUID);
  BLECharacteristic chr = svc.createCharacteristic(
    CHARACTERISTIC_UUID,
    BLEProperty::Read | BLEProperty::Write | BLEProperty::Notify,
    BLEPermission::ReadWriteOpen);
  // Notify auto-creates the CCCD on core 4.0; no BLE2902 descriptor needed.
  chr.onWrite([](BLECharacteristic &c, const BLEConnInfo &conn) {
    handleCommand(c.getStringValue());
  });
  server.start();
  BLE.getAdvertising().addServiceUUID(SERVICE_UUID);
  BLE.startAdvertising();
  Serial.println("BLE car advertising as ESP32-Robot-Car");
}

void loop() {
  // Stop if connected but silent for 2 seconds.
  if (deviceConnected && millis() - lastCommandMs > COMMAND_TIMEOUT_MS) {
    stopCar();
  }
  delay(50);
}

Test and tune it

Write F5 in nRF Connect and confirm both wheels spin forward while the car is lifted. Write S and confirm they stop. If nothing moves, check that the characteristic accepts writes and that the command letter is uppercase.

Write R5 and confirm the car turns right. If it turns left, swap the left and right motor wiring as a pair, or swap the L and R cases in handleCommand().

Switch the phone Bluetooth off while driving forward. The car should stop within a second. If it keeps driving, the disconnect callback is not registered, so check that onDisconnect is registered before server.start().

FAQ

Do I need an HC-05 module for Bluetooth on an ESP32?

No. The ESP32 DevKit V1 has Bluetooth Classic and BLE built in. This build uses native BLE, so no extra module is fitted and no second serial port is needed.

What phone app controls the car?

Any BLE scanner app that can write to a characteristic works. nRF Connect is free and shows the service, the characteristic, and the write box. A custom app with buttons is smoother, but it is not needed to test the build.

Why does the car stop when my phone locks?

Many phones drop BLE connections when the screen locks to save power. Keep the screen on while driving, or reconnect and write a new command after unlocking.

Can BLE and Wi-Fi run at the same time on an ESP32?

Yes, but they share the 2.4 GHz radio, so throughput drops when both are active. This build uses BLE only, so the radio is free for the car link.

How far can the phone control the car?

BLE range in open air is tens of meters, but walls and the metal chassis cut it. Test outdoors in open space, and keep the phone within a few meters for the first run.

Parts used

Build it with the ESP32 DevKit V1 Development Board, 30-Pin WROOM-32, the Smart Robot Car Chassis Kit with Speed Encoder and Battery Box for Arduino, 2WD / 4WD, and the L298N Dual H-Bridge Motor Driver Module for Arduino. The wired version is L298N Robot Car: Wire and Drive Two DC Motors, and the no-router radio version is ESP-NOW Joystick Robot Car: Two ESP32 Boards, No Router. For the chip radios behind the choice, see ESP32 vs ESP32-S3 vs ESP32-C3 vs ESP32-C6.

Sources

Last updated: 2026-11-21. Search volume: not verified. Product links use the store short link form with the product ID; confirm the product slug at publish time.

L298N Robot Car: Wire and Drive Two DC Motors

Phone showing a BLE control app next to an ESP32 robot car

L298N Robot Car: Wire and Drive Two DC Motors

Wire an L298N between your battery and two TT motors, then drive them from an ESP32 with PWM on the enable pins. The L298N handles up to 2 A per channel, drops about 2 V across the bridge, and needs its own motor supply. The ESP32 only sends low-current direction and speed signals, and the supplies share only a ground.

Quick facts

Item Value
Driver L298N dual H-bridge, 2 A per channel, 3 A peak non-repetitive for 100 ms
Motor supply 5 to 35 V on the module, up to 46 V on the bare chip
Logic supply 4.5 to 7 V; onboard 5 V regulator with jumper
Voltage drop 1.8 to 3.2 V at 1 A, up to 4.9 V at 2 A
Motors 2 x TT 130 gear motors, 3 to 6 V
Speed control PWM on ENA and ENB, 0 to 255

L298N robot car: what does the L298N do?

The L298N is a dual H-bridge driver built on the ST L298 chip. It lets a microcontroller run two DC motors in either direction, at variable speed, from a supply the microcontroller could never deliver itself. Each channel switches up to 2 A of continuous current, with a 3 A peak allowed only non-repetitively for 100 ms.

An H-bridge is four switches arranged so the motor current can flow either way. The IN1 and IN2 pins set the direction for the first motor, and IN3 and IN4 set it for the second. The ENA and ENB pins enable each channel, and a PWM signal on an enable pin sets the speed. With the enable jumpers fitted, each motor runs at full speed whenever the direction pins command movement.

The bridge is built from bipolar transistors, not MOSFETs, so it drops voltage. At 1 A the drop is 1.8 to 3.2 V, and at 2 A it reaches 4.9 V. That drop becomes heat in the chip, which is why the module carries a large heatsink. A 12 V supply gives the motor about 10 V. A 6 V supply gives the motor about 4 V.

When do you remove the 5 V jumper?

The module has an onboard 5 V regulator and a jumper that enables it. With the jumper fitted and a motor supply of 12 V or less, the regulator makes 5 V on the 5 V pin, and you can use that pin to power your logic. With a motor supply above 12 V, remove the jumper first, or the regulator overheats.

With the jumper removed, the 5 V pin becomes an input. You must feed 5 V into it yourself to power the chip logic. This build uses a 6 V motor pack, so the jumper stays on. The regulator then supplies the logic, and the ESP32 runs from its own USB supply.

Never connect two 5 V supplies to the same pin. If the jumper is fitted, leave the 5 V pin unconnected, or the regulator and your other supply will fight. If the jumper is removed, feed 5 V in and do not expect 5 V out.

How do you wire the L298N to an ESP32?

Connect the motor battery positive to the 12 V terminal and the battery negative to GND. Connect the two TT motors to OUT1 and OUT2 for the left motor, and OUT3 and OUT4 for the right motor. Connect ENA, IN1, IN2, ENB, IN3 and IN4 to the ESP32 pins in the wiring table.

The L298N inputs read high from 2.3 V, so the ESP32 3.3 V logic drives them directly. No level shifter is needed. Join the battery negative to the ESP32 ground. Without that common ground, the direction signals have no reference and the motors will not respond.

Remove the ENA and ENB jumpers before you connect PWM. With the jumpers fitted, the enable pins sit at 5 V and the motors run at full speed regardless of your code. With the jumpers removed, the ESP32 PWM signal on each enable pin sets the speed from 0 to 255.

How does PWM speed control work?

PWM switches the enable pin on and off about 1,000 times per second at the core 3.3.13 default of 1 kHz. The motor sees the average voltage, so a 50 percent duty cycle gives about half speed. The sketch below uses analogWrite() with values from 0 to 255. A value of 0 stops the motor, and 255 runs it at full speed for the supply voltage.

TT motors stall at low PWM values. Below about 80 out of 255, many TT motors do not turn at all, because the average voltage cannot overcome friction. Start your speed tests at 150 and work down. If the car creeps at low speed, that is normal for a geared TT motor on an L298N with a 2 V drop.

Direction and speed are separate. The IN pins set forward or reverse, and the enable PWM sets how fast. To stop, set the enable PWM to zero. To brake hard, set both IN pins the same way, but a simple stop is enough for a first build.

Wiring

Wire the build with the power off. Check every connection in the table before you connect any battery or USB cable.

From To Notes
Battery box positive L298N 12 V terminal Motor supply, 6 V from 4 AA cells
Battery box negative L298N GND and ESP32 GND Common ground is required
L298N OUT1, OUT2 Left TT motor Swap these two wires to fix a reversed wheel
L298N OUT3, OUT4 Right TT motor Swap these two wires to fix a reversed wheel
ESP32 GPIO 25 L298N ENA Remove the ENA jumper; PWM speed, left motor
ESP32 GPIO 27 L298N IN1 Left motor direction A
ESP32 GPIO 14 L298N IN2 Left motor direction B
ESP32 GPIO 26 L298N ENB Remove the ENB jumper; PWM speed, right motor
ESP32 GPIO 33 L298N IN3 Right motor direction A; GPIO 33 is used instead of GPIO 12, which is a flash-voltage strapping pin and must stay low at boot
ESP32 GPIO 13 L298N IN4 Right motor direction B
L298N 5 V pin Leave unconnected Jumper fitted at 6 V, so the regulator makes 5 V here; do not feed 5 V in as well
USB 5 V ESP32 USB port Logic supply only; motor current never passes through USB

Power budget

The motors run from 4 AA cells at about 6 V into the L298N. The bridge drops about 2 V, so each TT motor sees about 4 V. Two TT motors at full load draw about 1 to 2 A together, which the L298N handles with its heatsink. At 1 A per channel the chip dissipates about 2 W as heat, so give it airflow and do not cover the heatsink.

The ESP32 runs from USB 5 V and draws about 80 to 160 mA with the radio on. The L298N logic draws about 40 to 60 mA from the motor supply through its onboard regulator. The two supplies share only a ground wire. Never power the motors from the ESP32 5 V pin, and never power the ESP32 from the L298N 5 V pin while USB is also connected, because two 5 V sources will fight.

If you raise the motor supply above 12 V, remove the 5 V jumper first and feed 5 V into the 5 V pin yourself. Above 12 V the onboard regulator overheats. The TT motors in this build are rated 3 to 6 V, so a 6 V pack is the right match and the jumper stays on.

Build steps

  1. Assemble the chassis kit, fit the TT motors and wheels, and mount the L298N and the ESP32 on the top plate.
  2. Connect the motors to OUT1 and OUT2, and OUT3 and OUT4. Connect the battery box to the 12 V terminal and GND. Leave the 5 V jumper on for a 6 V pack.
  3. Remove the ENA and ENB jumpers. Wire the six control pins from the wiring table and join the battery negative to the ESP32 ground.
  4. Upload the sketch below to the ESP32 DevKit V1. Keep the car lifted off the floor for the first test.
  5. Open the serial monitor at 115200 baud and type f, b, l, r, or s, then press Enter. Each key drives the car forward, back, left, right, or stop.
  6. Set the car on the floor and drive it forward. If a wheel runs backward, swap that motor’s two wires at the L298N output.
  7. Test low speed. If the motors stall below a PWM value of about 80, raise your minimum drive speed in the sketch.

Code

Libraries: none beyond the ESP32 Arduino core. Board: ESP32 DevKit V1, Arduino core 3.3.13 (analogWrite arrived in core 3.0). Control the car from the serial monitor: type f, b, l, r, or s and press Enter.

// L298N robot car: two TT motors, PWM speed, serial control
// Board: ESP32 DevKit V1, Arduino core 3.3.13. No extra libraries needed.
const int ENA = 25;  // Left motor PWM (remove the ENA jumper)
const int IN1 = 27;  // Left motor direction A
const int IN2 = 14;  // Left motor direction B
const int ENB = 26;  // Right motor PWM (remove the ENB jumper)
const int IN3 = 33;  // Right motor direction A (GPIO 12 avoided: strapping pin)
const int IN4 = 13;  // Right motor direction B
const int SPEED = 200;  // 0 to 255; TT motors stall below about 80

void driveMotor(int pwmPin, int inA, int inB, int speed) {
  if (speed >= 0) {
    digitalWrite(inA, HIGH);
    digitalWrite(inB, LOW);
    analogWrite(pwmPin, speed);
  } else {
    digitalWrite(inA, LOW);
    digitalWrite(inB, HIGH);
    analogWrite(pwmPin, -speed);
  }
}

void drive(int left, int right) {
  driveMotor(ENA, IN1, IN2, left);
  driveMotor(ENB, IN3, IN4, right);
}

void stopCar() {
  analogWrite(ENA, 0);
  analogWrite(ENB, 0);
}

void setup() {
  Serial.begin(115200);
  pinMode(ENA, OUTPUT); pinMode(IN1, OUTPUT); pinMode(IN2, OUTPUT);
  pinMode(ENB, OUTPUT); pinMode(IN3, OUTPUT); pinMode(IN4, OUTPUT);
  stopCar();
  Serial.println("Type f, b, l, r, or s, then Enter.");
}

void loop() {
  if (Serial.available() > 0) {
    char c = Serial.read();
    if (c == 'f') drive(SPEED, SPEED);        // Forward
    else if (c == 'b') drive(-SPEED, -SPEED); // Reverse
    else if (c == 'l') drive(-SPEED, SPEED);  // Turn left
    else if (c == 'r') drive(SPEED, -SPEED);  // Turn right
    else if (c == 's') stopCar();             // Stop
  }
}

Test and tune it

Lift the car and type f. Both wheels should spin forward at the same speed. If one wheel is slower, check that its motor wires are tight in the screw terminal and that its enable PWM pin is connected.

Type s and confirm both wheels stop within a second. A wheel that keeps spinning has a stuck enable jumper or a shorted IN pin. Remove power and recheck the wiring table.

Drive the car on a hard floor, then on carpet. The car will slow on carpet because the TT motors draw more current under load and the L298N drop grows. That is normal. A MOSFET driver such as the TB6612FNG loses less voltage and is the next step if battery life matters.

FAQ

Why does my L298N get hot?

The bipolar bridge drops about 2 V, and that drop becomes heat. At 1 A per channel the chip dissipates about 2 W. The heatsink is supposed to get warm. Give it airflow and keep the current under 2 A per channel.

Do I remove the 5V jumper on the L298N?

Remove it when the motor supply is above 12 V, because the onboard regulator overheats. Leave it on at 12 V or less. With the jumper removed, feed 5 V into the 5 V pin yourself.

Why do the motors run slow on a 6 V battery?

The L298N drops about 2 V, so a 6 V pack gives each motor about 4 V. That is normal for this driver. A higher supply is not an option here: the pack is already 6 V and the TT motors are rated 3 to 6 V. A MOSFET driver such as the TB6612FNG loses less voltage and gives more speed.

Can the ESP32 drive the L298N directly?

Yes. The L298N inputs read high from 2.3 V, so 3.3 V logic works with no level shifter. Join the battery negative to the ESP32 ground so the signals share a reference.

Why does one wheel spin backward?

That motor is wired in reverse. Swap its two wires at the L298N output terminals. Do not fix it in code, because the wiring is the fault.

Parts used

Build it with the L298N Dual H-Bridge Motor Driver Module for Arduino, the Smart Robot Car Chassis Kit with Speed Encoder and Battery Box for Arduino, 2WD / 4WD, and the TT Motor 130 Gear Motor + 65mm Wheel, 3-6V DC, for Arduino Smart Car Robot, plus the ESP32 DevKit V1 Development Board, 30-Pin WROOM-32 as the controller. The wireless version is ESP-NOW Joystick Robot Car: Two ESP32 Boards, No Router, and the driver comparison is L298N vs TB6612 vs DRV8833: Which Motor Driver for Your Robot. For the driver behind the speed control, see How to Choose the Right Motor Drivers for Arduino Use.

Sources

Last updated: 2026-11-21. Search volume: not verified. Product links use the store short link form with the product ID; confirm the product slug at publish time.

ESP-NOW Joystick Robot Car: Two ESP32 Boards, No Router

Phone showing a BLE control app next to an ESP32 robot car

ESP-NOW Joystick Robot Car: Two ESP32 Boards, No Router

This ESP-NOW joystick robot car uses two ESP32 DevKit V1 boards. One board reads a PS2 joystick and sends drive commands with ESP-NOW. The other board receives them and drives two TT motors through an L298N. ESP-NOW needs no router, no Wi-Fi password, and no phone app, and the car stops by itself when the link drops.

Quick facts

Item Value
Boards 2 x ESP32 DevKit V1, 30-pin WROOM-32
Radio ESP-NOW, 2.4 GHz, up to 250 byte payloads in version 1
Motors 2 x TT 130 gear motors, 3 to 6 V
Driver L298N, 2 A per channel, 1.8 to 3.2 V drop at 1 A
Logic voltage 3.3 V on the ESP32; L298N inputs read high from 2.3 V
Failsafe Car stops if no packet arrives for 500 ms

ESP-NOW joystick robot car: what is ESP-NOW and why use it?

ESP-NOW is a connectionless protocol from Espressif that sends small packets directly from one ESP32 to another. It uses the 2.4 GHz radio, but it needs no access point, no router, and no IP address. The sender addresses the receiver by its MAC address, and the receiver answers with a callback when a packet lands.

A robot car is a good fit because the packets are small and the latency is low. A joystick sends two numbers, forward and turn, about 20 times per second. That fits in a packet of a few bytes. Wi-Fi with a web server also works, but it adds a router, a connection step, and a web page. Bluetooth also works, but it adds pairing and a phone app. ESP-NOW keeps the link between two boards you own.

The cost is range and pairing effort. ESP-NOW range in open air is similar to Wi-Fi range, and walls cut it fast. You must also copy the receiver MAC address into the sender sketch. That is a one-time step, and the build steps below show it.

How does the two-board layout work?

The remote board is an ESP32 DevKit V1 with a PS2 joystick module. It reads the joystick X and Y analog pins, maps them to speed and turn values, and sends one small struct with ESP-NOW. It sends 20 packets per second. It draws only the board current, about 80 mA on average and peaking near 240 mA while transmitting, from its USB supply or a small battery pack.

The car board is a second ESP32 DevKit V1 on the chassis. It receives the struct, converts speed and turn into left and right motor speeds, and writes PWM to the L298N enable pins. It also runs a watchdog timer. If 500 ms pass with no packet, it sets both motors to zero. That is the failsafe, and it matters when the car drives out of range or the remote battery dies.

Both boards must use the same Wi-Fi channel. ESP-NOW peers are registered on a channel, and the sender and receiver must agree. This build sets channel 1 on both boards. Keep the struct identical on both boards. If the sizes differ, the receiver reads garbage.

What parts do you need?

You need two ESP32 DevKit V1 boards, one robot car chassis kit, one L298N module, one PS2 joystick module, and jumper wires. The chassis kit in the parts list includes the frame, TT motors, wheels, a speed encoder, and a battery box. Use the battery box for the motors only, through the L298N, and power the car ESP32 from USB or a separate 5 V source during testing.

Do not power the motors from the ESP32 5 V pin. The TT motors draw far more current than a USB port or a board regulator can supply, and the voltage dips will reset the board. The L298N exists to keep motor current on its own supply. The wiring table below keeps the two supplies separate except for a shared ground.

How do you find the receiver MAC address?

Upload a short sketch to the car board that prints WiFi.macAddress() to the serial monitor at 115200 baud. Set WiFi.mode(WIFI_STA) first, because some cores print zeros before the mode is set. Copy the address from the monitor, for example A4:CF:12:34:56:78, and write it in the sender sketch as {0xA4, 0xCF, 0x12, 0x34, 0x56, 0x78}.

The sender registers that address as a peer with esp_now_add_peer(). The receiver needs no peer entry for a one-way link. It only registers a receive callback with esp_now_register_recv_cb(). The callback signature changed in Arduino core 3.0, so the code below uses a version guard for the receive callback. The sketch as a whole needs core 3.x (target 3.3.13, the stable 3.x release), because analogWrite does not exist in core 2.x. Core 4.0 is not verified for this sketch.

How does the joystick map to motor speed?

The joystick gives two analog readings, one for X and one for Y. Each reading runs 0 to 4095 on the ESP32 12-bit ADC. Center is near 2047. The sender subtracts the center, applies a dead zone of about 200 counts so a resting stick sends zero, and maps the result to a speed range of -255 to 255.

The car mixes speed and turn into left and right speeds. Left speed equals speed plus turn, and right speed equals speed minus turn. Each value is then clamped to -255 to 255. A positive value drives the motor forward, a negative value drives it in reverse, and zero stops it. The L298N direction pins set the direction, and the enable pin PWM sets the speed.

Test the mix on blocks before the car touches the floor. Lift the chassis, run the remote, and watch both wheels. Forward should spin both wheels forward. A right turn should slow or reverse the right wheel. If a wheel runs backward, swap its two motor wires at the L298N output, not in code.

Wiring

Wire the build with the power off. Check every connection in the table before you connect any battery or USB cable.

From To Notes
Joystick VCC Remote ESP32 3V3 3.3 V logic; the joystick module runs on 3.3 V or 5 V
Joystick GND Remote ESP32 GND Common ground
Joystick VRx Remote ESP32 GPIO 34 ADC1 pin; input only, safe with Wi-Fi running
Joystick VRy Remote ESP32 GPIO 35 ADC1 pin; input only, safe with Wi-Fi running
Joystick SW Remote ESP32 GPIO 32 Pushbutton; use INPUT_PULLUP and read LOW as pressed
Car ESP32 GPIO 25 L298N ENA PWM speed, left motor
Car ESP32 GPIO 26 L298N ENB PWM speed, right motor
Car ESP32 GPIO 27, 14 L298N IN1, IN2 Left motor direction, 3.3 V logic is enough; L298N reads high from 2.3 V
Car ESP32 GPIO 33, 13 L298N IN3, IN4 Right motor direction; GPIO 33 is used instead of GPIO 12, which is a flash-voltage strapping pin and must stay low at boot
L298N OUT1, OUT2 Left TT motor Motor wires; swap here to fix reversed direction
L298N OUT3, OUT4 Right TT motor Motor wires
Battery box positive L298N 12 V terminal Motor supply, 6 V from 4 AA cells; keep the 5 V jumper on at 12 V or less
Battery box negative L298N GND and car ESP32 GND Common ground is required; without it the L298N inputs float
USB 5 V Car ESP32 USB port Logic supply only; never route motor current through USB

Power budget

The car has two separate supplies. The motors run from 4 AA cells at about 6 V into the L298N. The L298N drops about 2 V, so each TT motor sees about 4 V. That is normal for this driver and is why a 6 V pack suits 3 to 6 V TT motors.

The car ESP32 runs from USB 5 V during testing. It draws about 80 to 160 mA with the radio on. The L298N logic draws about 40 to 60 mA from the motor supply through its own regulator when the 5 V jumper is fitted. Never feed the motors from the ESP32 5 V pin or from the same USB port that powers the board.

The remote ESP32 runs from USB 5 V. It draws about 80 mA on average, peaking near 240 mA while sending. A small USB power bank works for outdoor driving. Keep the remote and the car on the same ESP-NOW channel, channel 1 in the code below.

Build steps

  1. Assemble the chassis kit, fit the TT motors and wheels, and mount the L298N and the car ESP32 on the top plate.
  2. Wire the L298N outputs to the motors and the motor battery to the L298N 12 V terminal. Leave the 5 V jumper on for a 6 V pack.
  3. Wire the car ESP32 to the L298N control pins from the wiring table. Join the battery negative to the ESP32 ground.
  4. Upload the MAC print sketch to the car board, read its address from the serial monitor, and write it into the sender sketch.
  5. Upload the receiver sketch to the car board and the sender sketch to the remote board. Keep the struct identical in both files.
  6. Wire the joystick to the remote ESP32 from the wiring table. Power the remote from USB.
  7. Lift the car off the floor, push the stick forward, and confirm both wheels spin forward. Push right and confirm the right wheel slows.
  8. Set the car on the floor, drive it in a straight line, then walk away until it stops. The 500 ms failsafe should halt it when the link drops.

Code

Libraries: none beyond the ESP32 Arduino core (WiFi.h, esp_now.h and esp_wifi.h ship with the core). Board: ESP32 DevKit V1, Arduino core 3.3.13. analogWrite arrived in core 3.0, so core 2.x will not compile these sketches. Upload the receiver sketch to the car board first, then the sender sketch to the remote board.

// Receiver sketch: ESP-NOW robot car (car board)
// Board: ESP32 DevKit V1. Core: Arduino ESP32 3.x.
#include 
#include 
#include 

// Motor pins on the car board
const int ENA = 25;   // Left motor PWM
const int IN1 = 27;   // Left motor direction A
const int IN2 = 14;   // Left motor direction B
const int ENB = 26;   // Right motor PWM
const int IN3 = 33;   // Right motor direction A (GPIO 12 avoided: strapping pin)
const int IN4 = 13;   // Right motor direction B

// Must match the sender struct exactly, same order and types.
typedef struct {
  int16_t speed;  // -255 to 255, forward is positive
  int16_t turn;   // -255 to 255, right is positive
} DriveCommand;

DriveCommand cmd = {0, 0};
unsigned long lastPacketMs = 0;
const unsigned long FAILSAFE_MS = 500;  // Stop if no packet for 500 ms

void driveMotor(int pwmPin, int inA, int inB, int speed) {
  if (speed >= 0) {
    digitalWrite(inA, HIGH);
    digitalWrite(inB, LOW);
    analogWrite(pwmPin, speed);
  } else {
    digitalWrite(inA, LOW);
    digitalWrite(inB, HIGH);
    analogWrite(pwmPin, -speed);
  }
}

void stopMotors() {
  analogWrite(ENA, 0);
  analogWrite(ENB, 0);
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, LOW);
  digitalWrite(IN3, LOW);
  digitalWrite(IN4, LOW);
}

// Callback signature changed in Arduino core 3.0; this guard covers both.
#if ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(3, 0, 0)
void onReceive(const esp_now_recv_info_t *info, const uint8_t *data, int len) {
#else
void onReceive(const uint8_t *mac, const uint8_t *data, int len) {
#endif
  if (len == sizeof(cmd)) {
    memcpy(&cmd, data, sizeof(cmd));
    lastPacketMs = millis();
  }
}

void setup() {
  Serial.begin(115200);
  pinMode(ENA, OUTPUT); pinMode(IN1, OUTPUT); pinMode(IN2, OUTPUT);
  pinMode(ENB, OUTPUT); pinMode(IN3, OUTPUT); pinMode(IN4, OUTPUT);
  stopMotors();
  WiFi.mode(WIFI_STA);
  esp_wifi_set_channel(1, WIFI_SECOND_CHAN_NONE);  // Sender must use the same channel
  if (esp_now_init() != ESP_OK) {
    Serial.println("ESP-NOW init failed");
    return;
  }
  esp_now_register_recv_cb(onReceive);
  lastPacketMs = millis();
}

void loop() {
  if (millis() - lastPacketMs > FAILSAFE_MS) {
    stopMotors();  // Link lost: halt the car
    return;
  }
  int left = constrain(cmd.speed + cmd.turn, -255, 255);
  int right = constrain(cmd.speed - cmd.turn, -255, 255);
  driveMotor(ENA, IN1, IN2, left);
  driveMotor(ENB, IN3, IN4, right);
  delay(20);
}

// ---------- Sender sketch: ESP-NOW joystick remote ----------
// Board: ESP32 DevKit V1, Arduino core 3.3.13. Upload to the remote board.
// Replace receiverMac with the MAC address of the car board.
#include 
#include 
#include 

uint8_t receiverMac[] = {0xA4, 0xCF, 0x12, 0x34, 0x56, 0x78};  // Your car board

const int JOY_X = 34;  // ADC1 pin
const int JOY_Y = 35;  // ADC1 pin
const int JOY_SW = 32; // Pushbutton, INPUT_PULLUP

typedef struct {
  int16_t speed;  // Must match the receiver struct exactly
  int16_t turn;
} DriveCommand;

DriveCommand cmd = {0, 0};

int readAxis(int pin) {
  int v = analogRead(pin) - 2047;  // Center is near 2047
  if (v > -200 && v < 200) return 0;  // Dead zone
  return map(constrain(v, -2047, 2047), -2047, 2047, -255, 255);
}

void setup() {
  Serial.begin(115200);
  pinMode(JOY_SW, INPUT_PULLUP);
  WiFi.mode(WIFI_STA);
  esp_wifi_set_channel(1, WIFI_SECOND_CHAN_NONE);  // Receiver must use the same channel
  if (esp_now_init() != ESP_OK) {
    Serial.println("ESP-NOW init failed");
    return;
  }
  esp_now_peer_info_t peer = {};
  memcpy(peer.peer_addr, receiverMac, 6);
  peer.channel = 1;
  peer.encrypt = false;
  if (esp_now_add_peer(&peer) != ESP_OK) {
    Serial.println("Failed to add peer");
  }
}

void loop() {
  cmd.speed = readAxis(JOY_Y);  // Forward is positive
  cmd.turn = readAxis(JOY_X);   // Right is positive
  esp_now_send(receiverMac, (uint8_t *) &cmd, sizeof(cmd));
  delay(50);  // 20 packets per second
}

Test and tune it

Drive the car toward a wall at low speed and release the stick. The car should stop within half a second of the last packet. If it keeps rolling, the failsafe is not running, so check that lastPacketMs updates only inside the receive callback.

If one wheel spins backward, swap that motor's two wires at the L298N output. If the car turns left when you push right, swap the sign of the turn value in the sender, or swap the left and right motor wiring as a pair.

If packets stop arriving beyond a few feet indoors, check that both boards use channel 1 and that the receiver antenna area is clear of the metal chassis plate. Move the car board above the plate if the link is weak.

FAQ

Does ESP-NOW need a router?

No. ESP-NOW sends packets directly from one ESP32 to another by MAC address. It needs no router, no Wi-Fi password, and no internet connection.

What is the ESP-NOW range?

Range is similar to 2.4 GHz Wi-Fi in open air and drops fast through walls. Keep the receiver antenna clear of metal plates and test the failsafe at the edge of range.

Why does my car keep driving after I switch the remote off?

The receiver is not running a link-loss watchdog, or the watchdog timeout is too long. This build stops the motors after 500 ms with no packet. Check that lastPacketMs updates only in the receive callback.

Can I use ESP-NOW with an ESP32-S3 or ESP32-C3 as well?

Yes. ESP-NOW works across the ESP32 family, but the sender and receiver must use the same channel and the same struct. Check the pinout post for your exact board before you wire the L298N.

Why do the motors run slow on a 6 V pack?

The L298N drops about 2 V, so a 6 V pack gives each motor about 4 V. That is normal for this driver. A higher supply is not an option here: the pack is already 6 V and the TT motors are rated 3 to 6 V. Switch to a MOSFET driver such as the TB6612FNG for less drop.

Parts used

Build it with the ESP32 DevKit V1 Development Board, 30-Pin WROOM-32 (two boards, one for the remote and one for the car), the Smart Robot Car Chassis Kit with Speed Encoder and Battery Box for Arduino, 2WD / 4WD, the L298N Dual H-Bridge Motor Driver Module for Arduino, and the HiLetgo Game Joystick Sensor Module, PS2, 2-Axis with Pushbutton. The L298N robot car build in L298N Robot Car: Wire and Drive Two DC Motors covers the same driver in a wired build, and the ESP32 vs ESP32-S3 vs ESP32-C3 vs ESP32-C6 comparison helps if you pick a different board for the remote.

Sources

Last updated: 2026-11-21. Search volume: not verified. Product links use the store short link form with the product ID; confirm the product slug at publish time.

L298N vs TB6612 vs DRV8833: Which Motor Driver for Your Robot

L298N, TB6612FNG and DRV8833 motor driver boards side by side

L298N vs TB6612 vs DRV8833: Which Motor Driver for Your Robot

Pick the TB6612FNG for most battery robots. It drives two DC motors from 4.5 V to 13.5 V at 1.2 A average per channel, and it loses only about 0.5 V inside the chip at 1 A. Pick the DRV8833 when your battery stays under 10.8 V, and pick the L298N only when your motor supply runs above 13.5 V.

L298N vs TB6612 vs DRV8833 at a glance

The table below uses the ST L298 datasheet DS0218 Rev 5 (October 2023), the Toshiba TB6612FNG datasheet dated 2014-10-01, which prints no revision number, and the Texas Instruments DRV8833 datasheet SLVSAR1E Rev E (July 2015). Module ratings vary with board layout and cooling, so treat the continuous current figures as planning values, not guarantees.

Spec (unit) L298N TB6612FNG DRV8833
Switch type Bipolar Darlington MOSFET MOSFET
Motor supply (V) Up to 46 chip, 5 to 35 on common modules 4.5 to 13.5, 15 absolute max 2.7 to 10.8
Continuous current per channel (A) 2.0 1.2 average 1.5 RMS, PWP and RTY packages only (0.5 RMS in PW package), with good cooling
Peak current per channel (A) 3.0 non repetitive, 100 ms 3.2 single 10 ms pulse 2.0
Voltage lost at 1 A (V) 1.8 to 3.2 About 0.5, from 0.5 ohm on resistance About 0.36, from 0.36 ohm on resistance
Logic supply (V) 5, module regulator or Arduino 2.7 to 5.5 None needed, internal
Standby or sleep current 13 mA typ on VS, 24 mA typ on VSS (36 mA max on VSS) 1 uA max in standby 1.6 uA typ in sleep (2.5 uA max)
Channels (count) 2 DC motors or 1 stepper 2 DC motors or 1 stepper 2 DC motors or 1 stepper
Built in 5 V regulator Yes on common modules No No
Standby pin No, enable pins only Yes, STBY pin Yes, sleep via nSLEEP

Why does voltage drop decide this comparison?

A motor driver sits between the battery and the motor, and every volt it keeps is a volt the motor never sees. The L298N uses bipolar transistors, and the ST datasheet lists a total saturation drop of 1.8 V to 3.2 V at 1 A. On a 7.4 V battery with a motor drawing 1 A, the motor sees about 4.2 V to 5.6 V, and the missing 1.8 V to 3.2 V becomes heat in the driver. Heat is power lost: at 1 A and a 2 V drop, the driver burns 2 W per channel.

The MOSFET drivers lose far less. The TB6612FNG has about 0.5 ohm total on resistance, so at 1 A it drops about 0.5 V, and the heat is current squared times resistance, or 0.5 W per channel. The DRV8833 has about 0.36 ohm total on resistance, so at 1 A it drops about 0.36 V and burns about 0.36 W. On the same 7.4 V battery at 0.25 A per motor, the TB6612FNG delivers about 7.28 V and the DRV8833 about 7.31 V, while the L298N loses more than a volt at that current, so the motor sees less than the MOSFET drivers deliver. That is why a robot car runs faster and longer on a MOSFET driver with the same battery.

The practical rule is to size for stall current, not running current. A TT motor that draws 0.25 A while rolling can draw over 1 A when stalled against a wall. A driver rated for 1.2 A average per channel handles that stall briefly, but a driver run at its headline current for minutes overheats. Plan for roughly half the headline number for sustained running, and always check the stall current of your exact motor.

When should you pick the L298N?

Pick the L298N when the motor supply runs above 13.5 V. The TB6612FNG tops out at 15 V absolute maximum and the DRV8833 at 10.8 V, so a 24 V gear motor or a 12 V motor with a fully charged 4 cell LiPo that peaks above 16 V needs the L298N range. The L298N chip tolerates up to 46 V, and common modules are rated for 5 V to 35 V motor supplies.

The L298N module also suits a first build. It has screw terminals that accept thick motor wires without soldering, a heatsink, a built in 5 V regulator that can power an Arduino when the motor supply is under 12 V, and an enable jumper that every tutorial covers. Its 5 V jumper rule matters: with the jumper on and a motor supply under 12 V, the on board regulator outputs 5 V. Above 12 V, remove the jumper and power the logic separately, or the regulator overheats.

The cost of the L298N is heat and wasted battery. On a 7.4 V pack, about a quarter of the battery voltage never reaches the motor. On a 12 V supply the loss is a smaller share, so the L298N is at its best on 12 V builds and at its worst on small 2 cell battery robots.

When should you pick the TB6612FNG?

Pick the TB6612FNG for most small battery robots, including TT motor cars, N20 motor robots and 2WD chassis kits on 6 V to 12 V supplies. Its 4.5 V to 13.5 V range covers 4 AA cells, a 2 cell LiPo at 7.4 V and a 3 cell LiPo at 11.1 V. Its 1.2 A average and 3.2 A peak per channel cover TT and N20 stall currents with margin. Its STBY pin stops both motors with one logic line, which is the clean way to implement an emergency stop or a sleep mode.

The TB6612FNG logic supply runs from 2.7 V to 5.5 V, so it works directly with a 3.3 V ESP32 or a 5 V Arduino without a level shifter on the logic pins. Its low standby current, 1 uA max, suits a battery robot that sleeps between runs. Its only weakness is the 13.5 V ceiling: a 4 cell LiPo at full charge exceeds it, so a 4 cell build needs the L298N or a different driver.

When should you pick the DRV8833?

Pick the DRV8833 for compact, low voltage robots. Its 2.7 V to 10.8 V range starts at a single Li-ion cell, so a 1 cell robot at 3.7 V runs on it where the TB6612FNG needs at least 4.5 V. Its 1.5 A RMS and 2 A peak per channel in the PWP and RTY packages are the highest continuous current in this group, and its 0.36 ohm on resistance gives the lowest voltage drop and the least heat.

The DRV8833 needs no separate logic supply, because its logic runs from the motor supply internally, and it accepts 3.3 V and 5 V logic inputs. Its sleep current is 1.6 uA typ, close to the TB6612FNG standby current. Its weakness is the 10.8 V ceiling: a 3 cell LiPo at 11.1 V nominal and 12.6 V full charge exceeds it, so a 3 cell build belongs on the TB6612FNG or the L298N. It also has no built in 5 V regulator and no screw terminals on most breakout boards, so it suits a soldered build more than a first screw terminal build.

How do you wire each driver?

All three drivers use the same pattern: motor supply to VM or VS, logic supply where needed, ground shared with the microcontroller, two direction pins and one PWM enable pin per motor. On the L298N, the enable pins are ENA and ENB, and the direction pins are IN1 to IN4. On the TB6612FNG, the pins are PWMA and PWMB for speed, AIN1 and AIN2 plus BIN1 and BIN2 for direction, and STBY to enable the chip. On the DRV8833, the pins are AIN1 and AIN2 plus BIN1 and BIN2, and PWM goes on one input of each pair.

Three wiring rules apply to all three drivers. First, share the ground between the motor supply, the driver and the microcontroller, or the logic signals have no reference. Second, never power a motor from the microcontroller 5 V pin: use a separate battery or supply, and size it for the stall current. Third, add a 100 uF capacitor across the motor supply close to the driver on the TB6612FNG and DRV8833 boards, because motor current spikes pull the supply down and cause brownout resets.

Which driver for TT motors, N20 motors and 12 V builds?

Motor or build Pick this driver Why
TT motors, 3 to 6 V, 2WD car TB6612FNG Low drop on a small battery, 1.2 A covers stall, STBY pin
N20 motors, 3 to 6 V, small robot DRV8833 or TB6612FNG DRV8833 for 1 cell builds, TB6612FNG for 2 cell builds
12 V gear motors L298N Voltage headroom above 13.5 V, screw terminals, heatsink
3 cell LiPo, 11.1 V car TB6612FNG 13.5 V ceiling covers 12.6 V full charge, low drop
1 cell LiPo, 3.7 V robot DRV8833 Only driver here that starts at 2.7 V
First robot car, screw terminals L298N Screw terminals and 5 V regulator, simplest first wiring

For the L298N in practice, see the L298N robot car build.

FAQ

Can the L298N run on 3.3 V logic from an ESP32?

Yes, with care. The L298N logic high threshold is about 2.3 V, so a 3.3 V ESP32 output registers as high. Power the L298N logic from 5 V where the module expects it, share the ground, and keep the motor supply separate.

Why does my L298N get hot?

The L298N drops 1.8 V to 3.2 V at 1 A, and that power becomes heat. At 1 A per channel, the chip burns 1.8 W to 3.2 W per channel. Keep the heatsink on, improve airflow, or move to a MOSFET driver such as the TB6612FNG.

What is the STBY pin on the TB6612FNG?

STBY is the standby pin. Pull it low to stop both motors and drop the chip to 1 uA max. Pull it high to enable the driver. Tie it high through your code at startup, never leave it floating.

Can the DRV8833 drive a stepper motor?

Yes. The DRV8833 is a dual H-bridge, so it drives one bipolar stepper motor as well as two DC motors. It does not microstep; a stepper driver such as the A4988 is the pick when microstepping matters.

Do I need a flyback diode with these drivers?

No external flyback diodes are needed on these three boards, because the H-bridge transistors include body diodes that handle the motor inductive kick. A bulk capacitor across the motor supply is still good practice.

Parts used

L298N Dual H-Bridge Motor Driver Module: the rugged bipolar driver for 12 V and higher voltage builds. TB6612FNG Dual Motor Driver, 3-Pack: the MOSFET driver for most small battery robots. DRV8833 DC Motor Driver, 3-Pack: the low voltage MOSFET driver for 1 cell and 2 cell robots.

Sources

Last updated: 2026-11-21. Search volume: not verified. Product links use the store short link form with the product ID; confirm the product slug at publish time.