Arduino Mega - DRV8833 DC Motor Driver
This tutorial instructs you how to use the Arduino Mega 2560 to run small DC motors through a DRV8833 motor driver module. The Mega has 15 PWM pins, so giving the driver its four control signals still leaves plenty of PWM pins for servos, LEDs and other parts of a bigger robot. In detail, we will learn:
- What the DRV8833 is, and what each pin of the module does
- How the two IN pins of one channel set the direction, the speed, coast and brake
- How to connect the Arduino Mega 2560 to the DRV8833 and spin one DC motor
- How to program the Arduino Mega 2560 to drive two DC motors, like the wheels of a small robot car
We suggest:
- Utilizing the L298N driver if your motor needs more than 10.8V, such as a 12V motor.
- Utilizing the DC motor shield if you prefer a board that plugs straight on top of the Mega.

Hardware Preparation
Or you can buy the following kits:
| 1 | × | DIYables Sensor Kit (18 sensors/displays) |
Additionally, some of these links are for products from our own brand, DIYables .
The first part of this tutorial uses only one of the two motors.
Overview of DRV8833 DC Motor Driver
The DRV8833 is a small motor driver chip made by Texas Instruments. Inside it there are two H-bridges, so one module can run two brushed DC motors on its own, each one forward or backward at any speed. (It can also drive one small bipolar stepper motor, but this tutorial only covers DC motors.) The H-bridges are built from MOSFETs with a low resistance of about 360 mΩ. Compared with the older L298N, the voltage lost inside the driver is much smaller and the board stays cooler, which matters a lot when the motors run from a 6V battery pack.
| DRV8833 | |
|---|---|
| Motor supply voltage (VCC) | 2.7V to 10.8V |
| Logic voltage | 3.3V or 5V (no separate logic supply needed) |
| Output current per channel | about 1.5A continuous, 2A peak |
| Number of DC motors | 2 |
| Speed control | PWM on the IN pins, up to 50 kHz |
| Protection | under-voltage, over-current, over-temperature |
If one motor needs more current, the two channels can be joined in parallel for about 3A. This is an advanced setup, and we do not use it here.
The DRV8833 Motor Driver Module Pinout

The module has 12 pins. Labels vary between sellers: some boards print AIN1/AIN2/BIN1/BIN2, AOUT1/AOUT2/BOUT1/BOUT2, SLP and FLT instead of the names below.
Power pins:
- VCC pin: must be connected to the positive wire of the motor power supply (2.7V to 10.8V). This pin powers the motors only.
- GND pin: must be connected to the negative wire of the motor power supply and to GND of the Arduino Mega.
Control pins:
- IN1 and IN2 pins: must be connected to two PWM pins of the Arduino Mega. They control motor A.
- IN3 and IN4 pins: must be connected to two PWM pins of the Arduino Mega. They control motor B.
- EEP pin: the sleep pin. It must be HIGH for the driver to work. Connect it to the 5V pin of the Arduino Mega. If it is LOW, the chip sleeps and the motors do not move.
- ULT pin: the fault pin. It goes LOW when the chip detects a problem, such as too much current or too much heat. It is optional; you can leave it unconnected.
Motor pins:
- OUT1 and OUT2 pins: must be connected to the two wires of motor A.
- OUT3 and OUT4 pins: must be connected to the two wires of motor B.
※ NOTE THAT:
The arrangement of pins on a module may differ from one manufacturer to another. It is essential to always refer to the labels printed on the module when using it. Take a close look!
The chip makes its own internal logic voltage from VCC. This is why the module has no 5V logic pin, and why the 5V signals of the Arduino Mega can drive the IN pins directly.
How Two IN Pins Control One Motor
Unlike the L298N, the DRV8833 has no ENA or ENB pin. Each channel uses just two inputs, and the pair of levels decides what the motor does:
| IN1 | IN2 | Motor A |
|---|---|---|
| LOW | LOW | Coast - the motor is free and rolls to a stop |
| HIGH | LOW | Forward |
| LOW | HIGH | Reverse |
| HIGH | HIGH | Brake - the motor stops fast |
Motor B follows the same table with IN3 and IN4. To set the speed, the Arduino Mega sends a PWM signal to one IN pin and keeps the other one LOW. For forward, the PWM goes to IN1 while IN2 stays LOW. For reverse, IN1 stays LOW while the PWM goes to IN2. That is why both IN pins of a channel must be PWM pins.
The Arduino Mega has PWM on pins 2 to 13 and 44 to 46. In this tutorial we use pins 10 and 9 for motor A, and pins 6 and 5 for motor B. We skip pins 4 and 13, because their PWM runs at a different frequency (about 980 Hz instead of 490 Hz).
Power Supply for the Motors
Never power the motors from the 5V pin of the Arduino Mega. A motor can pull several hundred mA, and even more when it starts. This can reset the Mega or damage it. Use a separate supply on the VCC and GND pins of the module, for example:
- A 5V power adapter through a DC power jack, as used in this tutorial
- A pack of four AA batteries (about 6V), good for a robot car
The GND of the motor supply, the GND of the module and the GND of the Arduino Mega must all be connected together. Without a common ground, the IN signals have no reference, and the motors act strangely.
Part 1: Control One DC Motor
Wiring Diagram
Motor A is connected to OUT1 and OUT2, and the Arduino Mega sends its control signals from pins 10 and 9.

This image is created using Fritzing. Click to enlarge image
| DRV8833 Module | Connected To |
|---|---|
| IN1 | Arduino Mega pin 10 |
| IN2 | Arduino Mega pin 9 |
| EEP | Arduino Mega 5V |
| GND | Arduino Mega GND and the - wire of the 5V adapter |
| VCC | The + wire of the 5V adapter (via DC power jack) |
| OUT1 | DC motor wire 1 |
| OUT2 | DC motor wire 2 |
| ULT | Not connected |
How To Program For One DC Motor
No library is needed. The code uses only the built-in Arduino functions.
- The first step is to specify the two Arduino Mega pins that are connected to IN1 and IN2:
- Both pins are configured as outputs in the setup() function:
- To spin forward at a given speed (0 to 255), PWM is written to IN1 and IN2 is held LOW:
- To spin in reverse, the roles of the two pins are swapped:
- To let the motor coast, both pins are set LOW. To brake, both pins are set HIGH:
Arduino Mega 2560 Code for One DC Motor
The code below repeats these steps:
- Speeds the motor up from stop to full speed in the forward direction
- Holds full speed for 2 seconds
- Lets the motor coast to a stop
- Runs in reverse at about 70% speed for 2 seconds
- Brakes the motor
Detailed Instructions
- If this is the first time you use Arduino Mega 2560, see how to setup environment for Arduino Mega on Arduino IDE.
- Wire the components as shown in the diagram. Keep the 5V adapter unplugged for now.
- Connect the Arduino Mega board to your computer using a USB cable.
- Open Arduino IDE on your computer.
- Select the Arduino Mega or Mega 2560 board and the correct COM port.
- Copy the above code and paste it into the Arduino IDE.
- Click the Upload button to upload the code to the Arduino Mega.
- Plug in the 5V power adapter.
- Open the Serial Monitor and set the baud rate to 9600.
- Watch the motor and the Serial Monitor:
Listen to the motor during the two stops. After "Coast", it keeps turning for a short moment. After "Brake", it stops almost at once. If the motor turns the wrong way, swap its two wires on OUT1 and OUT2.
Part 2: Control Two DC Motors
Now let's use both channels. Think of a small two-wheel robot car: motor A drives the left wheel and motor B drives the right wheel. When both wheels turn the same way, the car goes straight. When they turn opposite ways, the car spins in place.
Wiring Diagram
Motor B is added on OUT3 and OUT4, and two more PWM pins of the Mega (6 and 5) go to IN3 and IN4.

This image is created using Fritzing. Click to enlarge image
| DRV8833 Module | Connected To |
|---|---|
| IN1 | Arduino Mega pin 10 |
| IN2 | Arduino Mega pin 9 |
| IN3 | Arduino Mega pin 6 |
| IN4 | Arduino Mega pin 5 |
| EEP | Arduino Mega 5V |
| GND | Arduino Mega GND and the - wire of the power supply |
| VCC | The + wire of the power supply |
| OUT1, OUT2 | Motor A (left wheel) |
| OUT3, OUT4 | Motor B (right wheel) |
Two motors draw about twice the current. A 5V adapter of 2A or more, or a 4xAA battery pack, is a good choice.
How To Program For Two DC Motors
Writing four pins by hand for every move gets long. The code uses one small helper function that takes a signed speed from -255 to 255:
- A positive value means forward, a negative value means reverse, and 0 means coast.
With this helper, each car move needs only two lines:
| Move | motorA() | motorB() |
|---|---|---|
| Forward | + speed | + speed |
| Backward | - speed | - speed |
| Turn left | - speed | + speed |
| Turn right | + speed | - speed |
| Stop | 0 | 0 |
Arduino Mega 2560 Code for Two DC Motors
Detailed Instructions
- Wire both motors as shown in the diagram above.
- Copy the code and paste it into the Arduino IDE.
- Click the Upload button to upload the code to the Arduino Mega.
- Plug in the motor power supply.
- Lift the car (or hold the motors) so the wheels can turn freely on your desk.
- Open the Serial Monitor and check the output:
If one wheel turns the wrong way during "forward", swap the two wires of that motor on the module. You do not need to change the code.
Additional Knowledge
DRV8833 vs L298N
| DRV8833 | L298N | |
|---|---|---|
| Motor voltage | 2.7V to 10.8V | 5V to 35V |
| Current per channel | about 1.5A | about 2A |
| Switch type | MOSFET | bipolar transistor |
| Voltage lost in the driver | small | about 2V or more |
| Heat | low | high, needs a big heatsink |
| Speed pins | none (PWM on IN pins) | ENA and ENB |
| Pins used on the Arduino Mega (2 motors) | 4 | 6 |
| Board size | very small | large |
It is evident that the DRV8833 is the better pick for small battery-powered robots running at 3V to 9V, because it wastes far less of the battery voltage. The L298N is still useful when the motor needs 12V or more.
Fault Pin (ULT)
If you want the Arduino Mega to know when the driver shuts down, connect the ULT pin to a digital input of the Mega and enable the internal pull-up with pinMode(pin, INPUT_PULLUP). The pin reads LOW during a fault, such as a short circuit or overheating, and HIGH when all is fine.