Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

ESP32-Controlled Dual DC Motor & Stepper Motor Driver System

View and Edit Project In Cirkit DesignerImage of ESP32-Controlled Dual DC Motor & Stepper Motor Driver System

Circuit Documentation

Summary

This circuit is designed to control two types of motors: a DC motor and a 28BYJ-48 stepper motor. The DC motor is driven by an L298N motor driver, which is controlled by an ESP32 microcontroller. The stepper motor is driven by a ULN2003A breakout board, also controlled by the ESP32. Power is supplied by two separate 9V batteries, each with a toggle switch for power control. The ESP32 microcontroller is programmed to control the speed and direction of the DC motor and can be adapted to control the stepper motor as well.

Component List

DC Motor

L298N DC Motor Driver

9V Battery

Toggle Switch

ESP32 (30 pin)

28BYJ-48 Stepper Motor

ULN2003A Breakout Board

Wiring Details

DC Motor

L298N DC Motor Driver

9V Battery

Toggle Switch

ESP32 (30 pin)

28BYJ-48 Stepper Motor

ULN2003A Breakout Board

Documented Code

// Motor A
int motor1Pin1 = 27; 
int motor1Pin2 = 26; 
int enable1Pin = 14; 

// Setting PWM properties
const int freq = 30000;
const int pwmChannel = 0;
const int resolution = 8;
int dutyCycle = 200;

void setup() {
  // sets the pins as outputs:
  pinMode(motor1Pin1, OUTPUT);
  pinMode(motor1Pin2, OUTPUT);
  pinMode(enable1Pin, OUTPUT);
  
  // configure LEDC PWM
  ledcAttachChannel(enable1Pin, freq, resolution, pwmChannel);

  Serial.begin(115200);

  // testing
  Serial.print("Testing DC Motor...");
}

void loop() {
  // Move the DC motor forward at maximum speed
  Serial.println("Moving Forward");
  digitalWrite(motor1Pin1, LOW);
  digitalWrite(motor1Pin2, HIGH); 
  delay(2000);

  // Stop the DC motor
  Serial.println("Motor stopped");
  digitalWrite(motor1Pin1, LOW);
  digitalWrite(motor1Pin2, LOW);
  delay(1000);

  // Move DC motor backwards at maximum speed
  Serial.println("Moving Backwards");
  digitalWrite(motor1Pin1, HIGH);
  digitalWrite(motor1Pin2, LOW); 
  delay(2000);

  // Stop the DC motor
  Serial.println("Motor stopped");
  digitalWrite(motor1Pin1, LOW);
  digitalWrite(motor1Pin2, LOW);
  delay(1000);

  // Move DC motor forward with increasing speed
  digitalWrite(motor1Pin1, HIGH);
  digitalWrite(motor1Pin2, LOW);
  while (dutyCycle <= 255){
    ledcWrite(enable1Pin, dutyCycle);   
    Serial.print("Forward with duty cycle: ");
    Serial.println(dutyCycle);
    dutyCycle = dutyCycle + 5;
    delay(500);
  }
  dutyCycle = 200;
}

This code is designed to control a DC motor using the ESP32 microcontroller. It sets up PWM for speed control and then cycles the motor forward, backward, and varies the speed. The pins used in the code correspond to the ESP32 microcontroller and must be connected to the appropriate pins on the L298N motor driver for proper operation.