Arduino Nano 33 IoT - DRV8833 DC Motor Driver

The Arduino Nano 33 IoT is a small 3.3V board, and it is a great brain for a light robot. To move wheels, it needs a motor driver. In this guide, we will use the tiny DRV8833 module for that job. We will go step by step:

Arduino Nano 33 IoT DRV8833 DC Motor Driver

Hardware Preparation

1×Arduino Nano 33 IoT
1×Micro USB Cable
1×DRV8833 Motor Driver Module
2×5V DC Motor (one for Part 1, two for Part 2)
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 is a dual H-bridge chip made by Texas Instruments. "Dual" means it has two separate channels, so one module can run two brushed DC motors on its own (or one small bipolar stepper motor, but we do not cover that here). Inside, it uses MOSFET switches with a low resistance of about 360 mΩ. Because of this, it wastes much less voltage and heat than the older L298N used in the Arduino Nano 33 IoT - DC Motor tutorial. This makes it a good match for small robots that run on 3V to 9V batteries.

The best part for the Nano 33 IoT: the DRV8833 has no separate logic supply. The chip makes its own internal logic voltage, so the 3.3V signals from the Nano 33 IoT work fine without any level shifter.

Key numbers of the DRV8833:

DRV8833
Motor supply (VCC pin) 2.7V to 10.8V
Output current per channel about 1.5A RMS, 2A peak (with good cooling)
Number of channels 2 (can be joined in parallel for about 3A on one motor)
PWM frequency up to 50 kHz
Protection under-voltage lockout, over-current, thermal shutdown

The DRV8833 Module Pinout

DRV8833 Motor Driver Module Pinout

The common breakout board has the following pins:

  • IN1, IN2 pins: control inputs for motor A. They must be connected to two PWM pins of the Arduino Nano 33 IoT.
  • IN3, IN4 pins: control inputs for motor B. They also must be connected to PWM pins.
  • OUT1, OUT2 pins: outputs that go to the two wires of motor A.
  • OUT3, OUT4 pins: outputs that go to the two wires of motor B.
  • VCC pin: motor power input, 2.7V to 10.8V. It must be connected to an external power supply, never to the Nano 33 IoT's pins.
  • GND pin: must be connected to the GND of the power supply AND the GND of the Arduino Nano 33 IoT.
  • EEP pin: the sleep pin (nSLEEP). It must be HIGH to turn the driver on. If it is LOW, the chip sleeps and the motors do not move. In this tutorial, we tie it to the 3.3V pin of the Nano 33 IoT.
  • ULT pin: the fault pin (nFAULT). It goes LOW when the chip detects a problem, such as overheating. It is optional, and we leave it unconnected.

※ NOTE THAT:

Pin labels vary from one maker to another. Some boards print AIN1, AIN2, BIN1, BIN2, AOUT1, AOUT2... and SLP / FLT instead of EEP / ULT. The job of each pin is the same. Always read the labels on your own module.

How the DRV8833 Controls a Motor

Unlike the L298N, the DRV8833 has no ENA / ENB enable pins. Both direction and speed come from the two IN pins of each channel. The table below shows the four states of motor A (motor B works the same way with IN3 and IN4):

IN1 IN2 Motor A
LOW LOW Coast - the power is cut, the motor rolls slowly to a stop
HIGH LOW Spins forward
LOW HIGH Spins in reverse
HIGH HIGH Brake - the motor stops quickly

To change the speed, we send a PWM signal to one IN pin and keep the other one LOW:

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

This is why all four IN pins must be PWM-capable. On the Arduino Nano 33 IoT, we use pins D10, D9, D6 and D5. They are all PWM pins on the same timer (TCC0), but each one has its own channel (CC3, CC2, CC0 and CC1), so every pin gets its own duty cycle.

PART 1: Control One DC Motor With the DRV8833

Wiring Diagram

The wiring diagram between Arduino Nano and 33 IoT DRV8833 one DC motor

This image is created using Fritzing. Click to enlarge image

DRV8833 Module Arduino Nano 33 IoT / Other
IN1 D10
IN2 D9
EEP 3.3V
GND GND (also GND of the 5V adapter)
VCC + of the 5V adapter (via DC power jack)
OUT1, OUT2 the two wires of the DC motor

※ NOTE THAT:

Do not power the motor from the 3.3V or VUSB pin of the Arduino Nano 33 IoT. Motors pull big current spikes that can reset or damage the board. Use the 5V power adapter, and make sure all the grounds are connected together.

How To Program For One DC Motor

  • The first step is to define the two Arduino Nano 33 IoT pins that are connected to IN1 and IN2:
#define PIN_IN1 10 #define PIN_IN2 9
  • Set both pins as outputs in setup():
pinMode(PIN_IN1, OUTPUT); pinMode(PIN_IN2, OUTPUT);
  • To run forward at a speed from 0 to 255, write PWM on IN1 and 0 on IN2:
analogWrite(PIN_IN1, speed); analogWrite(PIN_IN2, 0);
  • To run in reverse, swap the roles of the two pins:
analogWrite(PIN_IN1, 0); analogWrite(PIN_IN2, speed);
  • To brake, set both pins to full (255). To coast, set both pins to 0.

※ NOTE THAT:

On the Arduino Nano 33 IoT, once a pin has been used with analogWrite(), a later digitalWrite() on that pin does not change it. That is why the code uses analogWrite(pin, 0) for LOW and analogWrite(pin, 255) for HIGH everywhere, instead of mixing the two functions.

In the full code, these lines are packed into a small motorA(speed) function. It takes a signed speed: a positive value spins forward, a negative value spins in reverse, and 0 lets the motor coast.

Arduino Nano 33 IoT Code for One DC Motor

The code below repeats this sequence:

  • Speed up forward from 0 to full speed.
  • Hold full speed for 2 seconds.
  • Coast to a stop.
  • Spin in reverse at about 70% speed.
  • Brake hard.
/* * This Arduino Nano 33 IoT code was developed by newbiely.com * * This Arduino Nano 33 IoT code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-nano-iot/arduino-nano-33-iot-drv8833-dc-motor-driver */ // Pins of the Arduino Nano 33 IoT wired to channel A of the DRV8833 module. // Both pins must support PWM, because the speed is set on the IN pins. #define PIN_IN1 10 // The Arduino Nano 33 IoT pin connected to the IN1 pin of DRV8833 #define PIN_IN2 9 // The Arduino Nano 33 IoT pin connected to the IN2 pin of DRV8833 // Drive motor A with a signed speed: // +1 .. +255 -> forward (PWM on IN1, IN2 LOW) // -1 .. -255 -> reverse (IN1 LOW, PWM on IN2) // 0 -> coast (both pins LOW, motor rolls to a stop) // Note: on the Nano 33 IoT we use analogWrite() for every level (0 = LOW, 255 = HIGH). // Once a pin is used by analogWrite(), digitalWrite() does not control it any more. void motorA(int speed) { speed = constrain(speed, -255, 255); if (speed > 0) { analogWrite(PIN_IN1, speed); analogWrite(PIN_IN2, 0); } else if (speed < 0) { analogWrite(PIN_IN1, 0); analogWrite(PIN_IN2, -speed); } else { analogWrite(PIN_IN1, 0); analogWrite(PIN_IN2, 0); } } // Brake: both pins HIGH, the motor stops quickly void brakeA() { analogWrite(PIN_IN1, 255); analogWrite(PIN_IN2, 255); } void setup() { Serial.begin(9600); pinMode(PIN_IN1, OUTPUT); pinMode(PIN_IN2, OUTPUT); motorA(0); // start with the motor stopped } void loop() { // 1. Forward: ramp the speed up from 0 to full Serial.println("Forward: speeding up"); for (int speed = 0; speed <= 255; speed += 5) { motorA(speed); delay(40); } // 2. Hold full speed for 2 seconds Serial.println("Forward: full speed"); delay(2000); // 3. Coast: release the motor and let it roll to a stop Serial.println("Coast (free stop)"); motorA(0); delay(2000); // 4. Reverse at about 70% speed for 2 seconds Serial.println("Reverse: 70% speed"); motorA(-180); delay(2000); // 5. Brake: stop the motor fast Serial.println("Brake (fast stop)"); brakeA(); delay(2000); }

Detailed Instructions

If you are new to the Arduino Nano 33 IoT, be sure to check out our Getting Started with Arduino Nano 33 IoT tutorial. Then, follow these steps:

  • Wire the DRV8833, the motor and the power adapter as shown in the diagram. Keep the adapter unplugged for now.
  • Connect the Arduino Nano 33 IoT board to your computer using a USB cable.
  • Open Arduino IDE on your computer.
  • Select the Arduino Nano 33 IoT board and its COM port.
  • Copy the code above and paste it into the Arduino IDE.
  • Click the Upload button to compile and send the code to the board.
  • Plug in the 5V power adapter to power the motor.
  • Open the Serial Monitor and watch the motor:

- It slowly speeds up, then runs at full speed.

- It rolls freely to a stop.

- It turns the other way for 2 seconds.

- It stops sharply when the brake is applied.

∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
Arduino Nano 33 IoT
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'Arduino Nano 33 IoT' on 'COM15')
New Line
9600 baud
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 Nano 33 IoT on COM15
2

If the motor turns the "wrong" way, swap its two wires on OUT1 and OUT2. No code change is needed.

PART 2: Control Two DC Motors With the DRV8833

Now let's use both channels of the module. With one motor on each side, the Arduino Nano 33 IoT can drive a simple two-wheel robot car. To turn, one wheel goes forward while the other goes backward.

Wiring Diagram

The wiring diagram between Arduino Nano and 33 IoT DRV8833 two DC motors

This image is created using Fritzing. Click to enlarge image

DRV8833 Module Arduino Nano 33 IoT / Other
IN1 D10
IN2 D9
IN3 D6
IN4 D5
EEP 3.3V
GND GND (also GND of the 5V adapter)
VCC + of the 5V adapter (via DC power jack)
OUT1, OUT2 left motor (motor A)
OUT3, OUT4 right motor (motor B)

Two motors draw about twice the current of one. A 5V adapter of 2A or more is a safe choice. For a car that runs without a cable, a 4 x AA battery pack (about 6V) also works, since it stays inside the 2.7V to 10.8V range.

Arduino Nano 33 IoT Code for Two DC Motors

The code uses a helper for each channel, motorA(speed) and motorB(speed), with a signed speed from -255 to 255. On top of them, the drive() function sets both wheels, prints the action, and waits. The car goes forward, stops, goes backward, turns left, turns right, and stops again.

/* * This Arduino Nano 33 IoT code was developed by newbiely.com * * This Arduino Nano 33 IoT code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-nano-iot/arduino-nano-33-iot-drv8833-dc-motor-driver */ // Pins of the Arduino Nano 33 IoT wired to the DRV8833 module. // All four pins must support PWM. #define PIN_IN1 10 // Motor A (left wheel) - IN1 pin of DRV8833 #define PIN_IN2 9 // Motor A (left wheel) - IN2 pin of DRV8833 #define PIN_IN3 6 // Motor B (right wheel) - IN3 pin of DRV8833 #define PIN_IN4 5 // Motor B (right wheel) - IN4 pin of DRV8833 #define DRIVE_SPEED 200 // speed used for driving, 0 to 255 #define TURN_SPEED 160 // a bit slower for turning // Drive one DRV8833 channel with a signed speed (-255 .. 255). // Positive = forward, negative = reverse, 0 = coast. // analogWrite() is used for every level, so the pins stay in PWM mode. void driveChannel(int pinA, int pinB, int speed) { speed = constrain(speed, -255, 255); if (speed >= 0) { analogWrite(pinA, speed); analogWrite(pinB, 0); } else { analogWrite(pinA, 0); analogWrite(pinB, -speed); } } void motorA(int speed) { driveChannel(PIN_IN1, PIN_IN2, speed); } void motorB(int speed) { driveChannel(PIN_IN3, PIN_IN4, speed); } // Run both motors for a given time, and print what the car is doing void drive(const char *action, int speedA, int speedB, unsigned long duration) { Serial.println(action); motorA(speedA); motorB(speedB); delay(duration); } void setup() { Serial.begin(9600); pinMode(PIN_IN1, OUTPUT); pinMode(PIN_IN2, OUTPUT); pinMode(PIN_IN3, OUTPUT); pinMode(PIN_IN4, OUTPUT); motorA(0); motorB(0); } void loop() { drive("Car: forward", DRIVE_SPEED, DRIVE_SPEED, 2000); drive("Car: stop", 0, 0, 1000); drive("Car: backward", -DRIVE_SPEED, -DRIVE_SPEED, 2000); drive("Car: stop", 0, 0, 1000); drive("Car: turn left", -TURN_SPEED, TURN_SPEED, 1000); // A reverse, B forward drive("Car: turn right", TURN_SPEED, -TURN_SPEED, 1000); // A forward, B reverse drive("Car: stop", 0, 0, 2000); }

Detailed Instructions

  • Wire the second motor to OUT3 and OUT4, and connect IN3 and IN4 to D6 and D5, as shown in the diagram.
  • Connect the Arduino Nano 33 IoT to your computer with the USB cable.
  • Copy the code above into the Arduino IDE and click Upload.
  • Plug in the motor power supply.
  • Lift the wheels off the table for the first test, then open the Serial Monitor.
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
Arduino Nano 33 IoT
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'Arduino Nano 33 IoT' on 'COM15')
New Line
9600 baud
Car: forward Car: stop Car: backward Car: stop Car: turn left Car: turn right Car: stop Car: forward
Ln 11, Col 1
Arduino Nano 33 IoT on COM15
2

If one wheel turns the opposite way during "Car: forward", just swap the wires of that motor on its OUT pins.

Additional Knowledge

How is the DRV8833 different from the L298N? Here is a short comparison:

DRV8833 L298N
Motor voltage 2.7V to 10.8V about 5V to 35V
Switch type MOSFET (low loss) bipolar transistor (about 2V or more lost)
Speed control PWM on the IN pins PWM on the ENA / ENB pins
Size very small large, with a heat sink

It is evident that the DRV8833 is the better pick for small, low-voltage robots, while the L298N is still useful when the motors need 12V or more.

Video Tutorial

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