Cirkit Designer Logo
Cirkit Designer
Your all-in-one circuit design IDE
Home / 
Project Documentation

ESP32-Controlled Stepper Motor with ULN2003A Driver and 74HC595 Shift Register

Image of ESP32-Controlled Stepper Motor with ULN2003A Driver and 74HC595 Shift Register

Circuit Documentation

Summary

This circuit is designed to control a stepper motor using an ESP32 microcontroller. The stepper motor is driven by a ULN2003A driver board, which is in turn controlled by a 74HC595 shift register. The circuit allows for the motor to move forward and backward with 2048 steps per revolution at a speed of 5 steps per second. The ESP32 microcontroller receives commands via serial communication to control the motor's direction and number of steps.

Component List

ESP32 38 PINS

  • Description: A microcontroller with WiFi and Bluetooth capabilities and a wide range of GPIO pins.
  • Pins: GND, G23, G22, TXD, RXD, G21, G19, G18, G5, G17, G16, G4, G0, G2, G15, SDI, SD0, CLK, 3V3, EN, SP, SN, G34, G35, G32, 33, G25, G26, G27, G14, G12, G13, SD2, SD3, 5V

ULN2003A Breakout Board

  • Description: A breakout board for the ULN2003A, a 7-channel Darlington array used to drive high-current loads.
  • Pins: In 1, In 2, In 3, In 4, In 5, In 6, In 7, 0V, +5V, ON/OFF jumper switch, BLUE wire, PINK wire, YELLOW wire, ORANGE wire, RED wire

28BYJ-48 Stepper Motor

  • Description: A small, 5-wire, unipolar stepper motor with a 2048-step revolution.
  • Pins: BLUE, PINK, YELLOW, ORANGE, RED

5V Battery

  • Description: A power source providing a stable 5V output.
  • Pins: +, -

74HC595 Shift Register

  • Description: An 8-bit serial-in, serial or parallel-out shift register with output latches.
  • Pins: Q1, Q2, Q3, Q4, Q5, Q6, Q7, GND, VCC, Q0, DS (DATA), OE (Enable), ST_CP (RCLK), SH_CP (SRCLK), MR (SRCLR), Q7' (QH)

Wiring Details

ESP32 38 PINS

  • G27 connected to 74HC595 (CLOCK_PIN)
  • G14 connected to 74HC595 (LATCH_PIN)
  • G12 connected to 74HC595 (DATA_PIN)
  • GND connected to common ground
  • 5V connected to 5V power rail

ULN2003A Breakout Board

  • In 1 to In 4 connected to 74HC595 (Q0 to Q3)
  • 0V connected to common ground
  • +5V connected to 5V power rail
  • BLUE wire to 28BYJ-48 Stepper Motor (BLUE)
  • PINK wire to 28BYJ-48 Stepper Motor (PINK)
  • YELLOW wire to 28BYJ-48 Stepper Motor (YELLOW)
  • ORANGE wire to 28BYJ-48 Stepper Motor (ORANGE)
  • RED wire to 28BYJ-48 Stepper Motor (RED)

28BYJ-48 Stepper Motor

  • BLUE connected to ULN2003A (BLUE wire)
  • PINK connected to ULN2003A (PINK wire)
  • YELLOW connected to ULN2003A (YELLOW wire)
  • ORANGE connected to ULN2003A (ORANGE wire)
  • RED connected to ULN2003A (RED wire)

5V Battery

    • connected to 5V power rail
    • connected to common ground

74HC595 Shift Register

  • SH_CP (SRCLK) connected to ESP32 (CLOCK_PIN)
  • ST_CP (RCLK) connected to ESP32 (LATCH_PIN)
  • DS (DATA) connected to ESP32 (DATA_PIN)
  • OE (Enable) connected to common ground
  • GND connected to common ground
  • VCC connected to 5V power rail
  • MR (SRCLR) connected to 5V power rail
  • Q0 to Q7 connected to ULN2003A inputs (In 1 to In 4)
  • Q7' (QH) connected to the next 74HC595's DS (DATA) pin for daisy-chaining (if applicable)

Documented Code

/*
 * This Arduino sketch controls a stepper motor using an ESP32 microcontroller.
 * The stepper motor is driven by a ULN2003A driver board, which is controlled
 * via a 74HC595 shift register. The motor will move forward and backward with
 * 2048 steps per revolution and a speed of 5 steps per second.
 */

#include <Stepper.h>

// Define the control pins for the stepper motor
#define DATA_PIN 12
#define LATCH_PIN 14
#define CLOCK_PIN 27

// Number of steps per revolution
const int stepsPerRevolution = 2048;

// Initialize the Stepper library
Stepper stepper(stepsPerRevolution, DATA_PIN, CLOCK_PIN, LATCH_PIN);

void setup() {
  Serial.begin(115200); // Initialize serial communication
  stepper.setSpeed(5); // Set the speed to 5 steps per second
}

void loop() {
  if (Serial.available() > 0) {
    String command = Serial.readStringUntil('\n');
    processCommand(command);
  }
}

void processCommand(String command) {
  command.trim();
  if (command.startsWith("F")) {
    int steps = command.substring(1).toInt();
    moveMotor(steps);
  } else if (command.startsWith("B")) {
    int steps = command.substring(1).toInt();
    moveMotor(-steps);
  }
}

void moveMotor(int steps) {
  stepper.step(steps);
}

This code is designed to be uploaded to the ESP32 microcontroller. It sets up the stepper motor with the defined pins and initializes serial communication. The loop function listens for serial commands to move the motor forward (F) or backward (B) by a specified number of steps. The moveMotor function executes the movement command by stepping the motor the given number of steps.