Arduino Nano - DRV8833 DC Motor Driver

This tutorial instructs you how to use Arduino Nano with the DRV8833 motor driver module to spin small DC motors. In detail, we will learn:

Arduino Nano DRV8833 DC Motor Driver

We suggest:

Hardware Preparation

1×Official Arduino Nano
1×Alternatively, DIYables Nano V3.0 Development Board
1×USB A to Mini-B USB cable
1×DRV8833 Motor Driver Module
2×5V DC Motor
1×5V Power Adapter
1×DC Power Jack
1×Breadboard
1×Jumper Wires
1×Recommended: Screw Terminal Expansion Board for Arduino Nano
1×Recommended: Breakout Expansion Board for Arduino Nano
1×Recommended: Power Splitter for Arduino Nano

Or you can buy the following kits:

1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you.
Additionally, some of these links are for products from our own brand, DIYables .

Overview of DRV8833 Motor Driver

The DRV8833 Motor Driver Pinout

The DRV8833 is a dual H-bridge chip from Texas Instruments. One module can run two brushed DC motors on their own (it can also run one bipolar stepper motor, but that is outside this tutorial). The motor supply must be between 2.7V and 10.8V. Each channel delivers around 1.5A continuously and up to 2A for short peaks when it stays cool. Its outputs are MOSFETs with a low on-resistance (about 360 mΩ), so the voltage loss is small and the board stays much cooler than an L298N. This makes it a good choice for battery robots in the 3V to 9V range. The chip also protects itself against under-voltage, over-current and over-heating.

There is no separate logic power pin: the chip creates its own internal logic voltage from VCC. Therefore, the 5V signals coming out of the Arduino Nano are accepted directly.

DRV8833 motor driver module pinout

The DRV8833 module has twelve pins:

  • VCC pin: must be connected to the motor power supply (2.7V to 10.8V)
  • GND pin: must be connected to GND of the motor power supply AND GND of the Arduino Nano
  • EEP pin (nSLEEP): must be pulled HIGH to wake the driver up. Connect it to the 5V pin of the Arduino Nano. If it is LOW, the chip sleeps and the motors do not move
  • ULT pin (nFAULT): fault output. It goes LOW when the chip detects a problem. This pin is optional and can be left unconnected
  • IN1, IN2 pins: control inputs of motor A, used for both direction and speed
  • IN3, IN4 pins: control inputs of motor B, used for both direction and speed
  • OUT1, OUT2 pins: must be connected to the two wires of motor A
  • OUT3, OUT4 pins: must be connected to the two wires of motor B

※ NOTE THAT:

The arrangement and labels of pins may differ from one manufacturer to another. Some boards print AIN1/AIN2/BIN1/BIN2, AOUT1/AOUT2/BOUT1/BOUT2, SLP and FLT instead of the names above. It is essential to always refer to the labels printed on the module when using it. Take a close look!

How the DRV8833 Controls a Motor

Unlike the L298N, the DRV8833 has no ENA or ENB speed pin. The two IN pins of a channel set both the direction and the speed. The table below shows motor A (motor B works the same way with IN3 and IN4):

IN1 IN2 Motor A
LOW LOW Coast (the motor spins down freely)
HIGH LOW Forward
LOW HIGH Reverse
HIGH HIGH Brake (the motor stops quickly)

To change the speed, a PWM signal is sent to one of the two pins while the other stays LOW:

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

Because either pin may carry PWM, both IN pins of each channel must be connected to PWM-capable pins of the Arduino Nano. On the Arduino Nano, these pins are D3, D5, D6, D9, D10 and D11. If you want to brush up on how a DC motor and PWM work, see the Arduino Nano - DC Motor tutorial.

※ NOTE THAT:

  • Never power the motors from the 5V pin of the Arduino Nano. Use an external supply such as a 5V adapter or a pack of 4 AA batteries (about 6V).
  • The GND of the motor supply, the DRV8833 module and the Arduino Nano must be connected together. Without a common ground, the motors will behave strangely.
  • For heavier loads, the two channels can be wired in parallel for about 3A, but this is optional and not covered here.

Control One DC Motor with Arduino Nano and DRV8833

Wiring Diagram

The motor A wires go to OUT1 and OUT2, and the Arduino Nano drives IN1 from pin D10 and IN2 from pin D9.

The wiring diagram between Arduino Nano and DRV8833 one DC motor

This image is created using Fritzing. Click to enlarge image

DRV8833 Module Arduino Nano / Power
IN1 D10
IN2 D9
EEP 5V
GND GND (shared with the power supply)
VCC + of the 5V power adapter (via DC power jack)
OUT1, OUT2 Motor A wires

How To Program For DRV8833

  • The first step is to specify the Arduino Nano pins that are connected to IN1 and IN2:
const int IN1_PIN = 10; const int IN2_PIN = 9;
  • Set both pins as outputs in setup():
pinMode(IN1_PIN, OUTPUT); pinMode(IN2_PIN, OUTPUT);
  • To spin forward at a chosen speed (0 to 255), send PWM to IN1 and keep IN2 LOW:
analogWrite(IN1_PIN, speed); digitalWrite(IN2_PIN, LOW);
  • To spin in reverse, swap the roles of the two pins:
digitalWrite(IN1_PIN, LOW); analogWrite(IN2_PIN, speed);
  • To brake, set both pins HIGH. To coast, set both pins LOW:
digitalWrite(IN1_PIN, HIGH); // brake digitalWrite(IN2_PIN, HIGH);

Arduino Nano Code for DRV8833 - One DC Motor

The sketch below repeats these steps: it speeds the motor up, holds full speed, lets it coast, runs it in reverse, and finally brakes. Each step is printed to the Serial Monitor.

/* * This Arduino Nano code was developed by newbiely.com * * This Arduino Nano code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-nano/arduino-nano-drv8833-dc-motor-driver */ // Arduino Nano + DRV8833: control ONE DC motor (motor A) // The DRV8833 has no ENA pin. The speed is set by PWM on IN1 or IN2. const int IN1_PIN = 10; // The Arduino Nano pin connected to the IN1 pin of DRV8833 (PWM pin) const int IN2_PIN = 9; // The Arduino Nano pin connected to the IN2 pin of DRV8833 (PWM pin) void setup() { Serial.begin(9600); pinMode(IN1_PIN, OUTPUT); pinMode(IN2_PIN, OUTPUT); motorCoast(); // start with the motor free Serial.println("DRV8833 - one motor test started"); } void loop() { // 1. Forward: speed up slowly from 0 to 255 Serial.println("Forward: speeding up"); for (int speed = 0; speed <= 255; speed += 5) { motorForward(speed); delay(40); } // 2. Keep full speed for 2 seconds Serial.println("Forward: full speed"); delay(2000); // 3. Coast: both inputs LOW, the motor slows down by itself Serial.println("Coast (free stop)"); motorCoast(); delay(2000); // 4. Reverse at about 70% speed Serial.println("Reverse: speed 180"); motorReverse(180); delay(2000); // 5. Brake: both inputs HIGH, the motor stops fast Serial.println("Brake (fast stop)"); motorBrake(); delay(2000); } // Forward: PWM on IN1, IN2 stays LOW. speed = 0..255 void motorForward(int speed) { analogWrite(IN1_PIN, speed); digitalWrite(IN2_PIN, LOW); } // Reverse: IN1 stays LOW, PWM on IN2. speed = 0..255 void motorReverse(int speed) { digitalWrite(IN1_PIN, LOW); analogWrite(IN2_PIN, speed); } // Coast: IN1 = LOW, IN2 = LOW void motorCoast() { digitalWrite(IN1_PIN, LOW); digitalWrite(IN2_PIN, LOW); } // Brake: IN1 = HIGH, IN2 = HIGH void motorBrake() { digitalWrite(IN1_PIN, HIGH); digitalWrite(IN2_PIN, HIGH); }

Detailed Instructions

  • If this is the first time you use Arduino Nano, see how to setup environment for Arduino Nano on Arduino IDE.
  • Wire the components as shown in the diagram. Keep the 5V adapter unplugged for now.
  • Connect the Arduino Nano board to your computer using a USB cable.
  • Open Arduino IDE on your computer, then select the Arduino Nano board and its COM port.
  • Copy the code above and paste it into Arduino IDE.
  • Click the Upload button to upload the code to Arduino Nano.
  • Plug in the 5V adapter to power the motor.
  • Open the Serial Monitor and set the baud rate to 9600.
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
Arduino Nano
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'Arduino Nano' on 'COM15')
New Line
9600 baud
DRV8833 - one motor test started Forward: speeding up Forward: full speed Coast (free stop) Reverse: speed 180 Brake (fast stop) Forward: speeding up Forward: full speed
Ln 11, Col 1
Arduino Nano on COM15
2
  • Watch the motor: it ramps up, keeps spinning, slowly rolls to a stop, turns the other way, and then stops sharply when it brakes.

※ NOTE THAT:

If the motor turns the "wrong" way when the Serial Monitor says Forward, simply swap the two motor wires on OUT1 and OUT2.

Control Two DC Motors with Arduino Nano and DRV8833

Wiring Diagram

For the second motor, add four wires: motor B goes to OUT3 and OUT4, IN3 goes to pin D6 and IN4 goes to pin D5. The rest of the wiring stays the same.

The wiring diagram between Arduino Nano and DRV8833 two DC motors

This image is created using Fritzing. Click to enlarge image

See The best way to supply power to the Arduino Nano and other components.

DRV8833 Module Arduino Nano / Power
IN1 D10
IN2 D9
IN3 D6
IN4 D5
EEP 5V
GND GND (shared with the power supply)
VCC + of the 5V power adapter (via DC power jack)
OUT1, OUT2 Motor A (left wheel)
OUT3, OUT4 Motor B (right wheel)

Arduino Nano Code for DRV8833 - Two DC Motors

Think of the two motors as the left and right wheels of a small robot car. The code uses two helper functions, motorA(speed) and motorB(speed). The speed is a signed number from -255 to 255: a positive value turns the wheel forward, a negative value turns it backward, and 0 lets it coast. With these two functions, the car can move forward, move backward, turn left, turn right and stop.

/* * This Arduino Nano code was developed by newbiely.com * * This Arduino Nano code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-nano/arduino-nano-drv8833-dc-motor-driver */ // Arduino Nano + DRV8833: control TWO DC motors (like a small robot car) // Motor A = left wheel, Motor B = right wheel // All four IN pins must be PWM pins (3, 5, 6, 9, 10, 11 on the Arduino Nano) const int IN1_PIN = 10; // The Arduino Nano pin connected to the IN1 pin of DRV8833 (motor A) const int IN2_PIN = 9; // The Arduino Nano pin connected to the IN2 pin of DRV8833 (motor A) const int IN3_PIN = 6; // The Arduino Nano pin connected to the IN3 pin of DRV8833 (motor B) const int IN4_PIN = 5; // The Arduino Nano pin connected to the IN4 pin of DRV8833 (motor B) const int CAR_SPEED = 200; // 0..255 void setup() { Serial.begin(9600); pinMode(IN1_PIN, OUTPUT); pinMode(IN2_PIN, OUTPUT); pinMode(IN3_PIN, OUTPUT); pinMode(IN4_PIN, OUTPUT); stopCar(); Serial.println("DRV8833 - two motors test started"); } void loop() { Serial.println("Move forward"); motorA(CAR_SPEED); motorB(CAR_SPEED); delay(2000); Serial.println("Move backward"); motorA(-CAR_SPEED); motorB(-CAR_SPEED); delay(2000); Serial.println("Turn left"); motorA(-CAR_SPEED); // left wheel goes back motorB(CAR_SPEED); // right wheel goes forward delay(1000); Serial.println("Turn right"); motorA(CAR_SPEED); // left wheel goes forward motorB(-CAR_SPEED); // right wheel goes back delay(1000); Serial.println("Stop"); stopCar(); delay(2000); } // Drive one channel with a signed speed: // speed > 0 -> forward (PWM on the first pin, second pin LOW) // speed < 0 -> reverse (first pin LOW, PWM on the second pin) // speed == 0 -> coast (both pins LOW) void driveChannel(int pinA, int pinB, int speed) { speed = constrain(speed, -255, 255); if (speed > 0) { analogWrite(pinA, speed); digitalWrite(pinB, LOW); } else if (speed < 0) { digitalWrite(pinA, LOW); analogWrite(pinB, -speed); } else { digitalWrite(pinA, LOW); digitalWrite(pinB, LOW); } } // speed: -255..255 void motorA(int speed) { driveChannel(IN1_PIN, IN2_PIN, speed); } // speed: -255..255 void motorB(int speed) { driveChannel(IN3_PIN, IN4_PIN, speed); } void stopCar() { motorA(0); motorB(0); }

Detailed Instructions

  • Wire the second motor as shown in the diagram.
  • Connect the Arduino Nano board to your computer using a USB cable.
  • Copy the code above and open it in Arduino IDE.
  • Click the Upload button to upload the code to Arduino Nano.
  • Plug in the 5V adapter.
  • Open the Serial Monitor and watch both motors.
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
Arduino Nano
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'Arduino Nano' on 'COM15')
New Line
9600 baud
DRV8833 - two motors test started Move forward Move backward Turn left Turn right Stop Move forward Move backward
Ln 11, Col 1
Arduino Nano on COM15
2
  • To turn left, motor A runs backward while motor B runs forward. To turn right, it is the opposite.

Additional Knowledge

Let's compare the DRV8833 and the L298N motor drivers.

DRV8833 L298N
Motor voltage 2.7V to 10.8V 5V to 35V
Current per channel about 1.5A (2A peak) about 2A
Switching parts MOSFET bipolar transistor
Voltage loss and heat small large
Speed control pin no, PWM goes to IN pins yes, ENA and ENB
Logic power made inside the chip separate 5V pin
Board size very small large with heatsink

It is evident that the DRV8833 is the better fit for small, low-voltage battery robots, while the L298N is still needed for 12V or higher motors.

Video Tutorial

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!