Dual DC Motor Control With XIAO ESP32 C3 and DRV8833 Dual Motor Driver

by MertArduino in Circuits > Microcontrollers

186 Views, 0 Favorites, 0 Comments

Dual DC Motor Control With XIAO ESP32 C3 and DRV8833 Dual Motor Driver

Dual DC Motor Control with ESP32-C3 and DRV8833

Hi everyone! In this project, we will do the first setup of the XIAO ESP32-C3, a WiFi/Bluetooth dual-mode IoT mini development board, and perform a Blink test. Next, we will build a breadboard circuit and take a look at how to control dual DC motors with the DRV8833 motor driver module.

XIAO ESP32-C3

Ekran Resmi 2025-04-06 23.19.29.png
Ekran Resmi 2025-04-06 23.20.16.png
pin_map-2.png

To briefly mention XIAO, it is an IoT mini development board based on the Espressif ESP32-C3 WiFi/Bluetooth dual-mode chip. It has 11 digital input/output pins that can be used as PWM pins and 3 analogue input/output pins that can be used as ADC pins. It supports four different serial interfaces such as UART, I2C and SPI. One of its great features is that it supports lithium battery charge and discharge management. It also supports Arduino and MicroPython as programming languages.

Given these features, the XIAO ESP32 is positioned as a high-performance and cost-effective mini development board suitable for low power consumption IoT and wireless applications. More detailed technical specifications are available on the Seeed Studio Wiki page. As we use XIAO on a project basis, tips and details about its features will be included.

The package includes XIAO as well as an antenna and male headers. Depending on your usage preference and application, you can also use it without headers. However, for this project, the version with male pin headers will be preferred for modularity.

For more technical details: https://wiki.seeedstudio.com/XIAO_ESP32C3_Getting_Started/

First Setup & Blink

Ekran Resmi 2025-04-06 23.21.31.png
Ekran Resmi 2025-04-06 23.22.03.png
Ekran Resmi 2025-04-06 23.22.32.png
Ekran Resmi 2025-04-06 23.23.08.png
Ekran Resmi 2025-04-06 23.23.21.png
Ekran Resmi 2025-04-06 23.23.45.png
Ekran Resmi 2025-04-06 23.24.43.png
connect-led-2.png

To do the first setup, place the XIAO on a mini breadboard and connect it to your computer with a Type-C cable. Download and install the latest version of Arduino IDE for your operating system.

  1. Then go to File > Preferences, open the ‘Additional Board Manager URLs’ field and add the shared Arduino ESP32 link
https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
  1. Then go to Tools > Board > Board Manager, type ‘esp32’ in the search box and select the latest version for esp32 and install it.

After the installation is complete,

  1. Go to Tools > Board > ESP32 Arduino menu and select the ‘XIAO_ESP32C3’ board. The board list is quite long, so you may need to scroll down to find it.
  2. Then go to Tools > Port tab and select the serial port of the connected XIAO ESP32C3. Now XIAO is ready to upload code!

Open the Blink code shared in Arduino IDE. D10 pin is used in this code. Now let's add an LED to the circuit:

  1. Connect the long leg of the LED to the D10 pin and the short leg to the GND pin and place it on the breadboard.

Note that for long-term use, you should add a resistor in series to limit the current flowing through the LED. However, this is only a test application.

Finally, upload the Blink code to the XIAO. Now XIAO is ready to be programmed with Arduino IDE! Now let's move to the motor driver side.

// define led according to pin diagram in article
const int led = D10; // there is no LED_BUILTIN available for the XIAO ESP32C3.

void setup() {
// initialize digital pin led as an output
pinMode(led, OUTPUT);
}

void loop() {
digitalWrite(led, HIGH); // turn the LED on
delay(1000); // wait for a second
digitalWrite(led, LOW); // turn the LED off
delay(1000); // wait for a second
}

DRV8833 Dual Motor Driver Board

Ekran Resmi 2025-04-06 23.24.57.png
Ekran Resmi 2025-04-06 23.25.11.png
Ekran Resmi 2025-04-06 23.26.08.png
0J3866.1200.png

In the circuit, I preferred Pololu's DRV8833 dual motor driver board. Although the dimensions of the board are almost as small as an L293D motor driver chip, the features it offers are quite powerful compared to its size.

As a maker, I prefer pluggable boards in my circuits because it provides great convenience and flexibility in realising my projects. XIAO ESP32 C3 pins have a logic signal level of 3.3V. Some popular motor drivers, such as the L293D, require a logic level of 5V. However, the DRV8833 provides motor control at approximately 3V logic level, making it directly compatible with the XIAO ESP32 C3.

Furthermore, the DRV8833's operating voltage range is from 2.7V to 10.8V, making it compatible with a wide range of power supplies. Using this driver will benefit your projects in many ways.

For more technical details: https://www.pololu.com/product/2130

MH-MINI-360 Voltage Regulator

Ekran Resmi 2025-04-06 23.27.30.png
Ekran Resmi 2025-04-06 23.28.02.png
Ekran Resmi 2025-04-07 11.52.53.png

If we move to the power part of the circuit, I will use the small but functional MH-MINI-360 voltage regulator. Although the dimensions of the board are approximately the size of an L7805 regulator, it provides a great advantage in projects thanks to its adjustable voltage feature.

The input voltage is in the range of 4.5V to 23V and the output voltage can be adjusted between 1.25V and 20V. The output current is maximum 3 amps. This means that when used in conjunction with a motor driver, it can drive dual motors up to approximately 11V.

For more technical details: https://www.solarbotics.com/wp-content/uploads/mp2307.pdf

Now, let's move on to the next step and take a look at the breadboard circuit built with these three mini boards.

Breadboard Circuit

Ekran Resmi 2025-04-06 23.28.47.png
Ekran Resmi 2025-04-06 23.29.07.png
Ekran Resmi 2025-04-06 23.29.55.png
Ekran Resmi 2025-04-06 23.30.22.png
Ekran Resmi 2025-04-06 23.30.46.png
Ekran Resmi 2025-04-06 23.31.05.png
Ekran Resmi 2025-04-06 23.31.47.png
Ekran Resmi 2025-04-06 23.32.42.png
Ekran Resmi 2025-04-06 23.33.06.png
Ekran Resmi 2025-04-06 23.33.37.png
Ekran Resmi 2025-04-06 23.33.58.png
Ekran Resmi 2025-04-06 23.34.14.png
Ekran Resmi 2025-04-06 23.34.34.png
Ekran Resmi 2025-04-06 23.34.58.png
Ekran Resmi 2025-04-06 23.35.18.png
Ekran Resmi 2025-04-06 23.35.55.png
Breadboard-Circuit-XIAO-ESP32-C3-DRV8833-MH-MINI-360.png

I have already completed the wiring of the breadboard circuit, but I have shared a circuit diagram for you. You can access the circuit diagram from the video explanations. First, place MH-360-MINI board in the circuit, paying attention to the inputs and outputs of the voltage regulator. Then, place the DRV8833 motor driver board and finally add the XIAO ESP32 C3.

Now, we need to add a Schottky diode to the 5V pin of the XIAO ESP32 C3. You can choose 1N5819 as a Schottky diode. These diodes will be a good choice for low power consumption and low current draw boards like XIAO. I will explain the use of diodes in a moment.

The 5V pin of the XIAO can be used as a power input as well as a 5V output from the USB port. However, care should be taken when feeding it from an external power supply. A maximum of 5.5V should be supplied to the 5V pin. One of the main reasons for using a voltage regulator is to provide a stable 5V to the XIAO.

The purpose of using a diode is to prevent the 5V energy from USB from entering the circuit. Because the motors are connected to the same power line and feeding the motors via USB can damage the XIAO due to high current. Also, the diode ensures safety when feeding the XIAO with external 5V power. If an external power supply is connected while there is a USB connection, two different power supplies will send reverse current and this may damage the circuit.

Now, let's make the external power connections. I supply about 7.4V external power to the input of the voltage regulator. Earlier, I reduced the output voltage to about 5.6V using the potentiometer on the voltage regulator, so I supply 5.6V power to the circuit.

I add one capacitor between the 5V and GND pins of the XIAO. The capacitor helps to reduce the fluctuation of the power to the XIAO during the movement of the motors.

Finally, let's connect 2 5V DC Gear Motors to the circuit and complete our circuit. Next, we will move on to the source code for dual motor testing.

Source Code and Testing of Circuit

Ekran Resmi 2025-04-06 23.36.35.png
Ekran Resmi 2025-04-06 23.37.12.png
Ekran Resmi 2025-04-06 23.38.49.png

Get the shared source code and open it with Arduino IDE. Define the GPIO pins to which Motor 1 and Motor 2 are connected. Set the motor pins as ‘Output’ in the Setup section. When you look at the Loop section, you will see that the motors are controlled by PWM. PWM allows you to control the speed of the motors with analogue values. 0 command allows the motors to stop, 255 command allows the motors to rotate at maximum speed. You can change these values according to your needs. Now, let's load the code and test the circuit.

#include <Arduino.h> // Added necessary library

// Motor 1 and Motor 2 Pin Definitions
#define MOTOR1_IN1 3 // GPIO3
#define MOTOR1_IN2 4 // GPIO4
#define MOTOR2_IN1 6 // GPIO6
#define MOTOR2_IN2 7 // GPIO7

void setup() {
// Set motor pins as outputs
pinMode(MOTOR1_IN1, OUTPUT);
pinMode(MOTOR1_IN2, OUTPUT);
pinMode(MOTOR2_IN1, OUTPUT);
pinMode(MOTOR2_IN2, OUTPUT);
}

void loop() {
// Motor 1: Forward (speed control with PWM)
digitalWrite(MOTOR1_IN1, LOW); // Direction Forward
analogWrite(MOTOR1_IN2, 150); // Speed: between 0-255
digitalWrite(MOTOR2_IN1, LOW); // Direction Forward
analogWrite(MOTOR2_IN2, 150); // Speed: between 0-255
delay(2000); // Run for 2 seconds

// Stop motor 1
analogWrite(MOTOR1_IN1, 0);
analogWrite(MOTOR1_IN2, 0);
analogWrite(MOTOR2_IN1, 0);
analogWrite(MOTOR2_IN2, 0);
delay(2000); // Wait 2 seconds

// Motor 1: Reverse (speed control with PWM)
digitalWrite(MOTOR1_IN2, LOW); // Direction: Backward
analogWrite(MOTOR1_IN1, 150); // Speed: between 0-255
digitalWrite(MOTOR2_IN2, LOW); // Direction: Backward
analogWrite(MOTOR2_IN1, 150); // Speed: between 0-255
delay(2000);

// Stop motors
analogWrite(MOTOR1_IN2, 0);
analogWrite(MOTOR1_IN1, 0);
analogWrite(MOTOR2_IN2, 0);
analogWrite(MOTOR2_IN1, 0);
delay(2000); // Wait 2 seconds
}

As you can see, the XIAO is powered via USB but does not transfer power to the circuit through the diode. This protects the XIAO from possible high currents. Now, let's switch on the external power and test the motors. The dual motor driver breadboard circuit works without any problems.