Arduino UNO R4 - DC Motor
In this guide, we will learn how to use the Arduino UNO R4 to control the DC motor. In detail, we will learn:
- How a DC motor works
- How to control the speed and direction of a DC motor.
- Driving the DC motor with the help of a DRV8833 driver

Hardware Preparation
Or you can buy the following kits:
| 1 | × | DIYables STEM V4 IoT Starter Kit (Arduino included) | |
| 1 | × | DIYables STEM V4B IoT Starter Kit (Arduino included) | |
| 1 | × | DIYables Sensor Kit (18 sensors/displays) |
Additionally, some of these links are for products from our own brand, DIYables .
Overview of DC Motor
DC Motor Pinout
A DC motor has two wires.
- Positive wire: often red
- Negative wire: often black

How It Works
When you purchase a DC motor, it's important to understand which voltage it operates on. For instance, consider a DC motor that works on 12 volts. When you connect the 12V DC motor to a 12Volt power source:
- Connect 12V to the positive wire and GND to the negative wire: the DC motor will turn at full speed clockwise.
- Connect 12V to the negative wire and GND to the positive wire: the DC motor will turn at full speed counterclockwise.
When you switch the connections on two wires of the DC motor as mentioned earlier, the direction it spins changes. This technique helps control the direction of DC motor. This isn't done by hand, but rather through programming.
If we give less than 12V to DC motors, the motor turns but not at full speed. This shows that changing the voltage changes the motor's speed. But, adjusting the voltage directly is hard in real situations. So, there is a simpler method to control the speed of DC motor. We keep the power supply voltage constant and use a PWM (Pulse Width Modulation) signal to control the motor speed. With a higher PWM duty cycle, the motor spins faster, and vice versa.

The following animation shows how a PWM signal is used to control the speed of a DC motor:

How to control DC motor using Arduino UNO R4
To control a DC motor, you need to control its speed and direction. The Arduino UNO R4 can create a PWM signal, but this signal is too weak in voltage and current to control the motor directly. Therefore, a hardware driver is needed to connect the Arduino UNO R4 to the DC motor. This driver performs two main tasks:
- Increase the PWM signal's strength from the Arduino UNO R4 (both current and voltage) for controlling speed.
- Receive the control signal from the Arduino UNO R4 to change the power supply's polarity for controlling direction.

※ NOTE THAT:
- This guide uses a 5V DC motor. The DRV8833 driver works with motors from 2.7V to 10.8V. For a 12V motor, use a bigger driver. See Arduino UNO R4 - BTS7960 Motor Driver.
- When you use a 5V DC motor, even though the Arduino UNO R4 pin outputs 5V (the same voltage as the DC motor), you still need a driver between the Arduino UNO R4 and the DC motor. This is because the Arduino UNO R4 pin cannot supply enough current for the DC motor.
This tutorial will use the DRV8833 driver to control DC motors.
Overview of DRV8833 Driver
The DRV8833 is a tiny motor driver board. Inside its chip there are two H-bridges made of MOSFETs. One board can run two DC motors, or one bipolar stepper motor. In this guide, we use only one of its two channels.
Main facts:
- Motor supply on the VCC pin: 2.7V to 10.8V. A 5V adapter is a good match for a 5V motor.
- Output current: about 1.5A RMS per channel, 2A peak.
- Logic: works with 3.3V and 5V boards, so the Arduino UNO R4 can drive it directly.
- Protection: over-current, short circuit, thermal shutdown and under-voltage lockout.
- It is very small and needs no heat sink.
The MOSFET outputs lose almost no voltage. The older L298N lost about 2V inside, so a 5V motor got only about 3V. With the DRV8833, the motor gets nearly the full 5V and runs at its real speed.
DRV8833 Driver Pinout

The DRV8833 module has 12 pins in two rows.
Pins on the first side:
- IN1 & IN2 pins: inputs for motor A (channel A). They set the direction and the speed of motor A.
- VCC pin: the motor power supply, from 2.7V to 10.8V.
- GND pin: the common ground. Connect it to GND of the Arduino UNO R4 and to the negative pole of the power supply.
- IN3 & IN4 pins: inputs for motor B (channel B).
Pins on the other side:
- SLEEP pin (printed EEP on some boards): turns the chip on or off. It must be HIGH, or the chip sleeps and the motor does not move. The chip pulls this pin LOW inside, so do not leave it free. Connect it to the 5V pin of the Arduino UNO R4.
- OUT1 & OUT2 pins: connect to motor A.
- OUT3 & OUT4 pins: connect to motor B.
- FAULT pin: goes LOW when the chip finds a problem, such as too much current or too much heat. It is optional. We do not use it.
The DRV8833 has no ENA pin. Each IN pin sets both the direction and the speed. That is why both IN pins of a channel must go to PWM pins of the Arduino UNO R4.
One Arduino UNO R4 and one DRV8833 driver are enough to run two DC motors together, with two pins of the Arduino UNO R4 for each motor.
※ NOTE THAT:
This tutorial will show you how to control a DC motor using channel A. Controlling another DC motor is done in a similar way with IN3, IN4, OUT3 and OUT4.
Wiring Diagram
The motor gets its power from the 5V adapter, not from the Arduino UNO R4. The adapter plugs into the DC power jack. The jack's + goes to VCC and its - goes to GND of the DRV8833. The GND of the DRV8833 also goes to GND of the Arduino UNO R4, so all grounds are joined. One more short wire goes from the 5V pin of the Arduino UNO R4 to SLEEP, to wake the driver up.

This image is created using Fritzing. Click to enlarge image
| DRV8833 Pin | Arduino UNO R4 Pin / Other Part |
|---|---|
| IN1 | D10 |
| IN2 | D9 |
| SLEEP | 5V |
| GND | GND, and - of the 5V power adapter (through the DC power jack) |
| VCC | + of the 5V power adapter (through the DC power jack) |
| OUT1, OUT2 | the two wires of the DC motor |
| FAULT, IN3, IN4, OUT3, OUT4 | not connected |
A motor shakes the table, and jumper wires can slip out of the headers. To keep the wires tight, plug a Screw Shield V2 or a Proto Screw Terminal Block Shield into the Arduino UNO R4 and fix each wire under a screw. The pins stay the same, as you can see below.

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.
How To Control the Speed of DC Motor via DRV8833 Driver
To change the speed, send a PWM signal to one IN pin and keep the other IN pin LOW. The DRV8833 makes this PWM signal strong enough to power the DC motor. Here is how to do it:
- The DRV8833 gets its IN1 and IN2 signals from two Arduino UNO R4 pins that can output PWM.
- Use the analogWrite() function to send a PWM signal to IN1 (one direction) or to IN2 (the other direction).
The speed can be any number from 0 to 255. At a speed of 0, the motor will stop. At a speed of 255, the motor will rotate at its highest speed.
How To Control the Direction of DC Motor via DRV8833 Driver
The pin that gets the PWM signal decides the direction. The table below shows all four states of channel A.
| IN1 pin | IN2 pin | Direction |
|---|---|---|
| LOW | LOW | Motor A stops (coast, free stop) |
| HIGH | HIGH | Motor A stops (brake, fast stop) |
| PWM | LOW | Motor A spins Clockwise |
| LOW | PWM | Motor A spins Anti-Clockwise |
- Motor A rotates in a clockwise direction.
- Motor A turns counter-clockwise
In the code, we use analogWrite() with 0 for LOW and 255 for HIGH. So the IN pins always stay in PWM mode.
※ NOTE THAT:
If you connect the OUT1 and OUT2 pins to the DC motor pins in the opposite way, the motor will spin in the opposite direction. To fix this, simply switch the two motor wires on OUT1 and OUT2, or swap the IN1 and IN2 pins in the program code.
How To Stop DC Motor Spinning
There are two methods to turn off a DC motor.
- Coast: with LOW on IN1 as well as on IN2, the power is cut and the motor slows down by itself.
- Brake: HIGH on IN1 and HIGH on IN2 make the driver join the two motor wires together, so the motor stops very fast.
How to control a DC motor using DRV8833 driver.
Arduino UNO R4 Code
The code below does the following:
- Make the DC motor go faster
- Reverse the direction
- Make the DC motor go slower
- Stop the motor
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 components according to the provided diagram. Check that SLEEP goes to 5V. Keep the 5V adapter unplugged for now.
- 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 WiFi) and COM port.
- Paste the code into the Arduino IDE.
- Press the Upload button in the Arduino IDE to upload the code to the Arduino UNO R4.
- Plug the 5V adapter into the DC power jack to power the motor.
- Observations:
- The DC motor accelerates, then spins at maximum speed for 1 second.
- The direction of the DC motor changes.
- The DC motor spins at maximum speed for 1 second in the opposite direction.
- The DC motor decelerates.
- The DC motor stops for 1 second.
- This sequence repeats continuously.
※ NOTE THAT:
In this tutorial, we will learn how to adjust the relative speed of a DC motor in relation to its highest speed. To control the absolute speed in rotations per second, we must use a PID controller and an encoder. We will cover how to control the precise speed of the DC motor in a different tutorial.
No movement at all? Look at the SLEEP wire before anything else. When SLEEP is not HIGH, the DRV8833 sleeps.
To learn more about this driver, for example how to run two DC motors with one board, see Arduino UNO R4 - DRV8833 DC Motor Driver.