Maker 101
Published © LGPL

Dual DC Motor Control With ESP32 C3 and DRV8833 Driver

In this project, we will do the first setup of the XIAO ESP32-C3 and take a look at how to control dual DC motors with the DRV8833 driver.

BeginnerFull instructions provided1 hour278
Dual DC Motor Control With ESP32 C3 and DRV8833 Driver

Things used in this project

Hardware components

XIAO ESP32C3
Seeed Studio XIAO ESP32C3
×1
DV8833 Dual Motor Driver
×1
MH-MINI-360 Voltage Regulator
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Schematic

Code

motor-control-pwm.ino

Arduino
#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
}

Credits

Maker 101
56 projects • 187 followers
Maker 101; Beginner and intermediate level Maker projects!
Contact

Comments

Please log in or sign up to comment.