Arduino UNO R4 - DRV8833 DC Motor Driver

In this guide, we will learn how to drive DC motors from an Arduino UNO R4 with the small DRV8833 motor driver board. We start with a single motor, then we add a second motor, which is the base of a two-wheel robot car. In detail, we will learn:

Arduino UNO R4 DRV8833 DC motor driver

Overview of DRV8833 Motor Driver

A pin of the Arduino UNO R4 can only give a few milliamps, but a small DC motor needs hundreds. The DRV8833 board sits between them. It is built around a Texas Instruments chip with two H-bridges inside, so one board runs two brushed DC motors (it can also run one bipolar stepper motor). If you have read our Arduino UNO R4 - DC Motor tutorial with the L298N, you will see that the DRV8833 does the same job with a much smaller board.

Key facts:

DRV8833
Motor voltage (VCC pin) 2.7V to 10.8V
Logic signals 3.3V and 5V both work (no separate logic power pin)
Output current about 1.5A RMS per channel, 2A peak (with good cooling)
Output switches MOSFETs, about 360 mΩ (high side + low side)
PWM frequency up to 50 kHz
Protection under-voltage lockout, over-current, thermal shutdown

Because the outputs are MOSFETs, the voltage lost inside the driver is small. The older L298N loses a few volts as heat, but the DRV8833 passes almost all of the battery voltage to the motor. This makes it a good match for 3V to 9V battery robots. If you need more current for one big motor, the two channels can be joined in parallel for about 3A, but we do not do that in this guide.

DRV8833 motor driver pinout

The pins of the common red or blue DRV8833 module:

  • VCC pin: connect to the motor power supply (2.7V to 10.8V). The chip makes its own logic voltage from this pin.
  • GND pin: connect to the ground of the motor power supply and to GND of the Arduino UNO R4.
  • IN1, IN2 pins: control motor A. Connect to two PWM pins of the Arduino UNO R4.
  • IN3, IN4 pins: control motor B. Connect to two more PWM pins.
  • OUT1, OUT2 pins: connect to the two wires of motor A.
  • OUT3, OUT4 pins: connect to the two wires of motor B.
  • EEP pin (sleep pin, nSLEEP): must be HIGH to turn the driver on. Connect it to the 5V pin of the Arduino UNO R4. If it is LOW, the chip sleeps and the motors do not move.
  • ULT pin (fault pin, nFAULT): goes LOW when the chip detects a problem such as over-current or overheating. It is optional, and you can leave it unconnected.

※ NOTE THAT:

Pin labels vary between sellers. Some boards print AIN1/AIN2/BIN1/BIN2, AOUT1/AOUT2/BOUT1/BOUT2, SLP and FLT instead. The job of each pin stays the same.

How the IN pins control a motor

The L298N has ENA/ENB pins for speed. The DRV8833 has no such pin. Each channel uses only its two IN pins, and they set both the direction and the speed. Here is the table for motor A (motor B works the same with IN3 and IN4):

IN1 IN2 Motor A
LOW LOW Coast (power off, the motor rolls to a stop)
HIGH LOW Spins forward
LOW HIGH Spins in reverse
HIGH HIGH Brake (the motor stops quickly)

To change the speed, send a PWM signal instead of a steady HIGH:

  • Forward at a chosen speed: PWM on IN1, IN2 LOW.
  • Reverse at a chosen speed: IN1 LOW, PWM on IN2.

So both IN pins of a channel must be PWM pins. On the Arduino UNO R4 WiFi and Minima, the PWM pins are marked with a "~" sign. In this guide we use D10 and D9 for motor A, and D6 and D5 for motor B.

Powering the motors

Never run the motors from the 5V or 3.3V pin of the Arduino UNO R4. Power the VCC pin of the DRV8833 from a separate supply, such as a 5V adapter through a DC power jack, or a pack of 4 x AA batteries (about 6V). Then join the GND of that supply, the GND of the DRV8833 and the GND of the Arduino UNO R4 together. Without this common ground, the IN signals have no reference and the motors act strangely.

Part 1 - Control One DC Motor

Wiring Diagram

The wiring diagram between Arduino UNO R4 DRV8833 one DC motor

This image is created using Fritzing. Click to enlarge image

DRV8833 Module Arduino UNO R4 / other
IN1 D10
IN2 D9
EEP 5V
GND GND (and the negative of the 5V adapter)
VCC positive of the 5V adapter
OUT1, OUT2 the two wires of the DC motor

How To Program For DRV8833

  • Set the two pins that go to IN1 and IN2:
#define IN1_PIN 10 #define IN2_PIN 9
  • Make them outputs in setup():
pinMode(IN1_PIN, OUTPUT); pinMode(IN2_PIN, OUTPUT);
  • Spin forward at a speed from 0 to 255:
analogWrite(IN1_PIN, speed); analogWrite(IN2_PIN, 0);
  • Spin in reverse:
analogWrite(IN1_PIN, 0); analogWrite(IN2_PIN, speed);
  • Coast (both LOW) or brake (both HIGH):
analogWrite(IN1_PIN, 0); analogWrite(IN2_PIN, 0); // coast analogWrite(IN1_PIN, 255); analogWrite(IN2_PIN, 255); // brake

In the full code, these lines are wrapped in a small function motorA(speed). A positive speed means forward, a negative speed means reverse, and 0 means coast. We use analogWrite() with 0 and 255 for LOW and HIGH, so the same pins never switch between PWM mode and digital mode.

Arduino UNO R4 Code - One DC Motor

The code below:

  • Speeds up the motor slowly in the forward direction
  • Keeps full speed for 2 seconds
  • Lets the motor coast to a stop
  • Runs it in reverse at about 70% speed
  • Brakes it hard, then repeats
/* * This Arduino UNO R4 code was developed by newbiely.com * * This Arduino UNO R4 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-uno-r4/arduino-uno-r4-drv8833-dc-motor-driver */ // Arduino UNO R4 + DRV8833: control ONE DC motor (channel A) // Both IN pins must be PWM pins (marked with ~ on the board). #define IN1_PIN 10 // The Arduino UNO R4 pin connected to the IN1 pin of the DRV8833 #define IN2_PIN 9 // The Arduino UNO R4 pin connected to the IN2 pin of the DRV8833 // speed: -255 (full reverse) ... 0 (coast) ... 255 (full forward) void motorA(int speed) { speed = constrain(speed, -255, 255); if (speed > 0) { // forward: PWM on IN1, IN2 LOW analogWrite(IN1_PIN, speed); analogWrite(IN2_PIN, 0); } else if (speed < 0) { // reverse: IN1 LOW, PWM on IN2 analogWrite(IN1_PIN, 0); analogWrite(IN2_PIN, -speed); } else { // coast: both LOW, the motor slows down by itself analogWrite(IN1_PIN, 0); analogWrite(IN2_PIN, 0); } } // brake: both HIGH, the motor stops quickly void motorABrake() { analogWrite(IN1_PIN, 255); analogWrite(IN2_PIN, 255); } void setup() { Serial.begin(9600); pinMode(IN1_PIN, OUTPUT); pinMode(IN2_PIN, OUTPUT); motorA(0); // start with the motor stopped Serial.println("DRV8833 - one DC motor demo"); } void loop() { // 1. Speed up slowly in the forward direction Serial.println("Forward: speeding up"); for (int speed = 0; speed <= 255; speed += 5) { motorA(speed); delay(40); } // 2. Keep full speed for 2 seconds Serial.println("Forward: full speed"); delay(2000); // 3. Coast: cut the power and let the motor roll to a stop Serial.println("Coast (free stop)"); motorA(0); delay(1500); // 4. Run in reverse at about 70% speed Serial.println("Reverse: 70% speed"); motorA(-180); delay(2000); // 5. Brake: stop the motor fast Serial.println("Brake (fast stop)"); motorABrake(); delay(1500); }

Detailed Instructions

Follow these instructions step by step:

  • If this is your first time using the Arduino Uno R4 WiFi/Minima, refer to the tutorial on setting up the environment for Arduino Uno R4 WiFi/Minima in the Arduino IDE.
  • Wire the DRV8833 module, the DC motor and the 5V adapter according to the provided diagram. Check that EEP goes to 5V and that all grounds are joined.
  • Connect the Arduino Uno R4 board to your computer using a USB cable.
  • Launch the Arduino IDE on your computer.
  • Select the appropriate Arduino Uno R4 board (e.g., Arduino Uno R4 Minima) and COM port.
  • Copy the code above and paste it into the Arduino IDE.
  • Click the Upload button to send the code to the Arduino UNO R4.
  • Plug in the 5V adapter to power the motor.
  • Open the Serial Monitor and watch the motor.
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
Arduino Uno R4 WiFi
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'Arduino Uno R4 WiFi' on 'COM15')
New Line
9600 baud
DRV8833 - one DC motor demo Forward: speeding up Forward: full speed Coast (free stop) Reverse: 70% speed Brake (fast stop) Forward: speeding up Forward: full speed
Ln 11, Col 1
Arduino Uno R4 WiFi on COM15
2

Listen to the difference between the two stops: in the coast step the motor slows down softly, and in the brake step it stops almost at once.

※ NOTE THAT:

If the motor turns the wrong way, swap the two motor wires on OUT1 and OUT2. If the motor does not move at all, check the EEP pin first: when it is not HIGH, the driver sleeps.

Part 2 - Control Two DC Motors

Now we use channel B too. With one motor on the left wheel and one on the right wheel, the Arduino UNO R4 can steer a small car just by changing the direction of each wheel.

Wiring Diagram

The wiring diagram between Arduino UNO R4 DRV8833 two DC motors

This image is created using Fritzing. Click to enlarge image

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

DRV8833 Module Arduino UNO R4 / other
IN1 D10
IN2 D9
IN3 D6
IN4 D5
EEP 5V
GND GND (and the negative of the 5V adapter)
VCC positive of the 5V adapter
OUT1, OUT2 motor A (left wheel)
OUT3, OUT4 motor B (right wheel)

Arduino UNO R4 Code - Two DC Motors

This code adds a motorB(speed) function and a drive() helper that sets both motors and prints the action name. The car moves forward, stops, moves backward, then turns left (motor A in reverse, motor B forward) and right (the opposite).

/* * This Arduino UNO R4 code was developed by newbiely.com * * This Arduino UNO R4 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-uno-r4/arduino-uno-r4-drv8833-dc-motor-driver */ // Arduino UNO R4 + DRV8833: control TWO DC motors, like a small robot car // All four IN pins must be PWM pins (marked with ~ on the board). #define IN1_PIN 10 // Motor A (left wheel) - DRV8833 IN1 #define IN2_PIN 9 // Motor A (left wheel) - DRV8833 IN2 #define IN3_PIN 6 // Motor B (right wheel) - DRV8833 IN3 #define IN4_PIN 5 // Motor B (right wheel) - DRV8833 IN4 #define DRIVE_SPEED 200 // driving speed, 0 to 255 // Set one channel. speed: -255 (full reverse) ... 0 (coast) ... 255 (full forward) void setChannel(int pinA, int pinB, int speed) { speed = constrain(speed, -255, 255); if (speed >= 0) { analogWrite(pinA, speed); // forward (or coast when speed is 0) analogWrite(pinB, 0); } else { analogWrite(pinA, 0); // reverse analogWrite(pinB, -speed); } } void motorA(int speed) { setChannel(IN1_PIN, IN2_PIN, speed); } void motorB(int speed) { setChannel(IN3_PIN, IN4_PIN, speed); } // Run one action for a given time and print its name void drive(const char *action, int speedA, int speedB, unsigned long ms) { Serial.println(action); motorA(speedA); motorB(speedB); delay(ms); } void setup() { Serial.begin(9600); pinMode(IN1_PIN, OUTPUT); pinMode(IN2_PIN, OUTPUT); pinMode(IN3_PIN, OUTPUT); pinMode(IN4_PIN, OUTPUT); Serial.println("DRV8833 - two DC motors demo"); } void loop() { drive("Move forward", DRIVE_SPEED, DRIVE_SPEED, 2000); drive("Stop", 0, 0, 1000); drive("Move backward", -DRIVE_SPEED, -DRIVE_SPEED, 2000); drive("Stop", 0, 0, 1000); drive("Turn left", -DRIVE_SPEED, DRIVE_SPEED, 800); // A reverse, B forward drive("Stop", 0, 0, 1000); drive("Turn right", DRIVE_SPEED, -DRIVE_SPEED, 800); // A forward, B reverse drive("Stop", 0, 0, 2000); }

Detailed Instructions

  • Add the second motor and the IN3/IN4 wires as shown in the diagram above.
  • Copy the code and open it in the Arduino IDE.
  • Click the Upload button to upload the code to the Arduino UNO R4.
  • Power the motors with the 5V adapter.
  • Open the Serial Monitor. Lift the wheels off the table so the car does not run away while you test.
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
Arduino Uno R4 WiFi
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'Arduino Uno R4 WiFi' on 'COM15')
New Line
9600 baud
DRV8833 - two DC motors demo Move forward Stop Move backward Stop Turn left Stop Turn right Stop Move forward
Ln 11, Col 1
Arduino Uno R4 WiFi on COM15
2

If the car turns right when the Serial Monitor says "Turn left", one motor is wired the other way round. Swap the wires of that motor on its OUT pins.

※ NOTE THAT:

Two motors take more current than one. If the Arduino UNO R4 resets when both motors start, your supply is too weak. Use a stronger adapter or fresh batteries, and keep the motor supply separate from the USB power.

Video Tutorial

Function References

※ 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!