Arduino - DRV8833 DC Motor Driver

In this tutorial, we are going to learn:

Arduino DRV8833 DC Motor Driver

If you have not used a DC motor before, the Arduino - DC Motor tutorial explains how speed and direction work with the bigger L298N driver.

Hardware Required

1×Official Arduino Uno
1×Alternatively, DIYables STEM V3, Fully Compatible with Arduino Uno R3
1×USB 2.0 cable type A/B (for USB-A PC)
1×USB 2.0 cable type C/B (for USB-C PC)
1×DRV8833 Motor Driver Module
2×5V DC Motor
1×5V Power Adapter
1×DC Power Jack
1×Jumper Wires
1×Recommended: Screw Terminal Block Shield for Arduino Uno
1×Recommended: Sensors/Servo Expansion Shield for Arduino Uno
1×Recommended: Breadboard Shield for Arduino Uno
1×Recommended: Enclosure for Arduino Uno
1×Recommended: Prototyping Base Plate & Breadboard Kit for Arduino UNO

Or you can buy the following kits:

1×DIYables STEM V3 Starter Kit (Arduino included)
1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some links in this section are Amazon affiliate links. If you make a purchase through these links, we may earn a commission at no extra cost to you.
Additionally, some links direct to products from our own brand, DIYables .

For PART 1, one DC motor is enough. The second motor is only needed for PART 2.

About DRV8833 Motor Driver

The DRV8833 is a small chip from Texas Instruments with two H-bridges inside. One H-bridge can turn one brushed DC motor in both directions, so the module drives two DC motors (or one small bipolar stepper motor, but that is not covered here). Its outputs are MOSFETs with a very low resistance, about 360 mΩ. Because of this, the motor gets almost the full battery voltage and the chip stays cool. The old L298N loses about 2V inside itself, so the DRV8833 is a better choice for robots that run on 3V to 9V batteries.

DRV8833 Motor Driver Pinout
DRV8833
Motor Supply Voltage (VCC) 2.7V to 10.8V
Logic Input Voltage 3.3V or 5V (no separate logic supply)
Output Current 1.5A RMS per channel, 2A peak
Number of Channels 2 (motor A and motor B)
PWM Frequency up to 50 kHz
Protection under-voltage, over-current, over-temperature

The common DRV8833 module has these pins:

  • VCC pin: needs to be connected to the positive wire of the motor power supply (2.7V to 10.8V)
  • GND pin: needs to be connected to GND of the power supply and GND of Arduino
  • IN1, IN2 pins: control motor A. They need to be connected to two PWM pins of Arduino
  • IN3, IN4 pins: control motor B. They need to be connected to two other PWM pins of Arduino
  • OUT1, OUT2 pins: connect to the two wires of motor A
  • OUT3, OUT4 pins: connect to the two wires of motor B
  • EEP pin: the sleep pin (nSLEEP). It needs to be HIGH to turn the driver on. We connect it to 5V of Arduino. If it is LOW, the chip sleeps and the motors do not move.
  • ULT pin: the fault pin (nFAULT). It goes LOW when there is a problem like too much current or heat. We can leave it unconnected.

The labels are not the same on every module. Some boards print AIN1, AIN2, BIN1, BIN2, AOUT1, AOUT2... for the inputs and outputs, and SLP and FLT for the sleep and fault pins. The functions are the same.

Unlike the L298N, the DRV8833 does not need a 5V logic supply from Arduino. The chip makes its own logic voltage from VCC. Arduino only needs to share the same GND.

How To Control a Motor With Two Pins

There is no ENA or ENB speed pin on the DRV8833. Each motor is controlled by just two input pins. The table below shows what happens for motor A (motor B works the same with IN3 and IN4):

IN1 IN2 Motor A
LOW LOW Coast (motor spins freely and slows down by itself)
HIGH LOW Forward
LOW HIGH Reverse
HIGH HIGH Brake (motor stops quickly)

To set the speed, we send a PWM signal to one input and keep the other input LOW:

  • Forward with speed: PWM on IN1, IN2 is LOW
  • Reverse with speed: IN1 is LOW, PWM on IN2

This is why both pins of a motor must be PWM pins. On Arduino Uno, the PWM pins are 3, 5, 6, 9, 10 and 11.

※ NOTE THAT:

  • Never power the motors from the 5V pin of Arduino. Motors need much more current than Arduino can give. Use an external power supply.
  • The GND of the power supply, the DRV8833 and Arduino must be connected together.
  • If a motor spins in the wrong direction, just swap its two wires on the OUT pins.

PART 1: Arduino Controls One DC Motor With DRV8833

Wiring Diagram

Arduino DRV8833 one DC motor wiring diagram

This image is created using Fritzing. Click to enlarge image

Wiring table of DRV8833 Module and Arduino Uno

DRV8833 Module Arduino Uno / Other
IN1 → Pin 10
IN2 → Pin 9
EEP → 5V
GND → GND (and GND of the 5V power adapter)
VCC → positive (+) of the 5V power adapter via the DC power jack
OUT1, OUT2 → the two wires of the DC motor

How To Program For DRV8833

  • Define the Arduino pins connected to IN1 and IN2:
#define AIN1_PIN 10 #define AIN2_PIN 9
  • Set the pins as outputs:
pinMode(AIN1_PIN, OUTPUT); pinMode(AIN2_PIN, OUTPUT);
  • Run the motor forward with a speed from 0 to 255:
digitalWrite(AIN2_PIN, LOW); analogWrite(AIN1_PIN, speed);
  • Run the motor in reverse:
digitalWrite(AIN1_PIN, LOW); analogWrite(AIN2_PIN, speed);
  • Let the motor coast to a stop:
digitalWrite(AIN1_PIN, LOW); digitalWrite(AIN2_PIN, LOW);
  • Brake the motor:
digitalWrite(AIN1_PIN, HIGH); digitalWrite(AIN2_PIN, HIGH);

Arduino Code - DRV8833 One DC Motor

The below code does:

  • Speed the motor up slowly in the forward direction
  • Run at full speed for 2 seconds
  • Coast to a stop
  • Run in reverse at a medium speed
  • Brake to a fast stop
  • Repeat again and again
/* * Created by ArduinoGetStarted.com * * This example code is in the public domain * * Tutorial page: https://arduinogetstarted.com/tutorials/arduino-drv8833-dc-motor-driver */ // Arduino Uno pins connected to the DRV8833 module (both must be PWM pins) #define AIN1_PIN 10 // the Arduino pin connected to the IN1 pin of DRV8833 #define AIN2_PIN 9 // the Arduino pin connected to the IN2 pin of DRV8833 // the setup function runs once when you press reset or power the board void setup() { Serial.begin(9600); pinMode(AIN1_PIN, OUTPUT); pinMode(AIN2_PIN, OUTPUT); motorCoast(); // make sure the motor is not moving at start Serial.println("DRV8833 is ready"); } // the loop function runs over and over again forever void loop() { // 1. Speed up slowly in the forward direction Serial.println("Forward: speeding up"); for (int speed = 0; speed <= 255; speed += 5) { motorForward(speed); delay(40); } // 2. Keep the full speed for 2 seconds Serial.println("Forward: full speed"); delay(2000); // 3. Coast: the motor slows down by itself Serial.println("Coast (free stop)"); motorCoast(); delay(1500); // 4. Run backward at about 70% speed Serial.println("Reverse: speed 180"); motorReverse(180); delay(2000); // 5. Brake: the motor stops quickly Serial.println("Brake (fast stop)"); motorBrake(); delay(1500); } // forward: PWM on IN1, IN2 is LOW. speed: 0 to 255 void motorForward(int speed) { digitalWrite(AIN2_PIN, LOW); analogWrite(AIN1_PIN, speed); } // reverse: IN1 is LOW, PWM on IN2. speed: 0 to 255 void motorReverse(int speed) { digitalWrite(AIN1_PIN, LOW); analogWrite(AIN2_PIN, speed); } // coast: both inputs LOW -> motor outputs are off void motorCoast() { digitalWrite(AIN1_PIN, LOW); digitalWrite(AIN2_PIN, LOW); } // brake: both inputs HIGH -> motor wires are shorted, fast stop void motorBrake() { digitalWrite(AIN1_PIN, HIGH); digitalWrite(AIN2_PIN, HIGH); }

Quick Steps

  • Do the wiring as shown in the diagram above. Plug in the 5V power adapter last.
  • Connect Arduino to PC via USB cable
  • Open Arduino IDE, select the right board and port
  • Copy the above code and open with Arduino IDE
  • Click Upload button on Arduino IDE to upload code to Arduino
  • Watch the motor: it speeds up, runs, coasts, turns back and brakes
  • Open the Serial Monitor to see what the motor is doing at each moment
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
Arduino Uno
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'Arduino Uno' on 'COM15')
New Line
9600 baud
DRV8833 is ready Forward: speeding up Forward: full speed Coast (free stop) Reverse: speed 180 Brake (fast stop) Forward: speeding up Forward: full speed Coast (free stop)
Ln 11, Col 1
Arduino Uno on COM15
2

Look at the difference between the two stops. After "Coast", the motor keeps turning for a short time. After "Brake", it stops almost at once.

PART 2: Arduino Controls Two DC Motors With DRV8833

With two motors, we can build the base of a small robot car: motor A is the left wheel and motor B is the right wheel.

Wiring Diagram

Arduino DRV8833 two DC motors wiring diagram

This image is created using Fritzing. Click to enlarge image

Wiring table of DRV8833 Module and Arduino Uno

DRV8833 Module Arduino Uno / Other
IN1 → Pin 10
IN2 → Pin 9
IN3 → Pin 6
IN4 → Pin 5
EEP → 5V
GND → GND (and GND of the 5V power adapter)
VCC → positive (+) of the 5V power adapter via the DC power jack
OUT1, OUT2 → motor A (left)
OUT3, OUT4 → motor B (right)

How To Program For Two DC Motors

To keep the code short, we use one helper function for each motor. It takes a signed speed:

  • A positive value (1 to 255) runs the motor forward
  • A negative value (-1 to -255) runs the motor in reverse
  • 0 lets the motor coast
motorA(200); // left wheel forward motorB(-200); // right wheel backward

To turn the car, the two wheels spin in opposite directions:

  • Turn left: motor A reverse, motor B forward
  • Turn right: motor A forward, motor B reverse

Arduino Code - DRV8833 Two DC Motors

The below code moves the car forward, backward, turns left, turns right and then stops.

/* * Created by ArduinoGetStarted.com * * This example code is in the public domain * * Tutorial page: https://arduinogetstarted.com/tutorials/arduino-drv8833-dc-motor-driver */ // Arduino Uno pins connected to the DRV8833 module (all four are PWM pins) #define AIN1_PIN 10 // IN1 - motor A (left wheel) #define AIN2_PIN 9 // IN2 - motor A (left wheel) #define BIN1_PIN 6 // IN3 - motor B (right wheel) #define BIN2_PIN 5 // IN4 - motor B (right wheel) #define CAR_SPEED 200 // driving speed, from 0 to 255 void setup() { Serial.begin(9600); pinMode(AIN1_PIN, OUTPUT); pinMode(AIN2_PIN, OUTPUT); pinMode(BIN1_PIN, OUTPUT); pinMode(BIN2_PIN, OUTPUT); stopCar(); Serial.println("Two-motor car is ready"); } void loop() { Serial.println("Car: forward"); motorA(CAR_SPEED); motorB(CAR_SPEED); delay(2000); Serial.println("Car: backward"); motorA(-CAR_SPEED); motorB(-CAR_SPEED); delay(2000); Serial.println("Car: turn left"); motorA(-CAR_SPEED); // left wheel goes back motorB(CAR_SPEED); // right wheel goes forward delay(1000); Serial.println("Car: turn right"); motorA(CAR_SPEED); // left wheel goes forward motorB(-CAR_SPEED); // right wheel goes back delay(1000); Serial.println("Car: stop"); stopCar(); delay(2000); } // control motor A. speed: -255 (full reverse) to 255 (full forward), 0 = coast void motorA(int speed) { setMotor(AIN1_PIN, AIN2_PIN, speed); } // control motor B. speed: -255 (full reverse) to 255 (full forward), 0 = coast void motorB(int speed) { setMotor(BIN1_PIN, BIN2_PIN, speed); } // shared helper for one DRV8833 channel void setMotor(int in1, int in2, int speed) { speed = constrain(speed, -255, 255); if (speed > 0) { // forward: PWM on IN1, IN2 LOW digitalWrite(in2, LOW); analogWrite(in1, speed); } else if (speed < 0) { // reverse: IN1 LOW, PWM on IN2 digitalWrite(in1, LOW); analogWrite(in2, -speed); } else { // coast: both LOW digitalWrite(in1, LOW); digitalWrite(in2, LOW); } } // stop both motors quickly (brake: both inputs HIGH) void stopCar() { digitalWrite(AIN1_PIN, HIGH); digitalWrite(AIN2_PIN, HIGH); digitalWrite(BIN1_PIN, HIGH); digitalWrite(BIN2_PIN, HIGH); }

Quick Steps

  • Do the wiring for two motors as shown in the diagram above
  • Connect Arduino to PC via USB cable
  • Copy the above code and open with Arduino IDE
  • Click Upload button on Arduino IDE to upload code to Arduino
  • Lift the wheels off the table (or put the car on the floor with enough space)
  • See the result on Serial Monitor
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
Arduino Uno
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'Arduino Uno' on 'COM15')
New Line
9600 baud
Two-motor car is ready Car: forward Car: backward Car: turn left Car: turn right Car: stop Car: forward Car: backward
Ln 11, Col 1
Arduino Uno on COM15
2

※ NOTE THAT:

If the car turns right when it should turn left, swap the two wires of one motor on its OUT pins, or swap motor A and motor B in the code.

Video Tutorial

We are considering to make the video tutorials. If you think the video tutorials are essential, please subscribe to our YouTube channel to give us motivation for making the videos.

The Best Arduino Starter Kit

※ OUR MESSAGES