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

Arduino-Controlled Dual Stepper Motor System with Bluetooth Interface

Image of Arduino-Controlled Dual Stepper Motor System with Bluetooth Interface

Circuit Documentation

Summary

This circuit is designed to control two 28BYJ-48 stepper motors using an Arduino UNO microcontroller and two ULN2003A breakout boards. The Arduino UNO is programmed to receive commands via its serial interface to control the direction and state (running or stopped) of the stepper motors. The ULN2003A breakout boards serve as the driving interface between the low-power Arduino digital outputs and the higher-power requirements of the stepper motors.

Component List

Arduino UNO

  • Description: A microcontroller board based on the ATmega328P.
  • Purpose: Acts as the central controller for the circuit, executing the embedded code to control the stepper motors.

28BYJ-48 Stepper Motor (x2)

  • Description: A small, 5-wire, unipolar stepper motor.
  • Purpose: Converts electrical pulses into discrete mechanical movements.

ULN2003A Breakout Board (x2)

  • Description: A board containing the ULN2003A Darlington transistor array, used for driving stepper motors.
  • Purpose: Interfaces between the Arduino UNO and the stepper motors, providing the necessary current and voltage levels.

Wiring Details

Arduino UNO

  • D8: Connected to ULN2003A breakout board In 1 (Motor 1)
  • D9: Connected to ULN2003A breakout board In 2 (Motor 1)
  • D10: Connected to ULN2003A breakout board In 3 (Motor 1)
  • D11: Connected to ULN2003A breakout board In 4 (Motor 1)
  • D4: Connected to ULN2003A breakout board In 1 (Motor 2)
  • D5: Connected to ULN2003A breakout board In 2 (Motor 2)
  • D6: Connected to ULN2003A breakout board In 3 (Motor 2)
  • D7: Connected to ULN2003A breakout board In 4 (Motor 2)

28BYJ-48 Stepper Motor 1

  • BLUE: Connected to ULN2003A breakout board BLUE wire (Motor 1)
  • PINK: Connected to ULN2003A breakout board PINK wire (Motor 1)
  • YELLOW: Connected to ULN2003A breakout board YELLOW wire (Motor 1)
  • ORANGE: Connected to ULN2003A breakout board ORANGE wire (Motor 1)
  • RED: Connected to ULN2003A breakout board RED wire (Motor 1)

28BYJ-48 Stepper Motor 2

  • BLUE: Connected to ULN2003A breakout board BLUE wire (Motor 2)
  • PINK: Connected to ULN2003A breakout board PINK wire (Motor 2)
  • YELLOW: Connected to ULN2003A breakout board YELLOW wire (Motor 2)
  • ORANGE: Connected to ULN2003A breakout board ORANGE wire (Motor 2)
  • RED: Connected to ULN2003A breakout board RED wire (Motor 2)

ULN2003A Breakout Board 1 (Motor 1)

  • In 1 - In 4: Connected to Arduino UNO pins D8 - D11 respectively
  • BLUE wire - RED wire: Connected to corresponding wires of Stepper Motor 1

ULN2003A Breakout Board 2 (Motor 2)

  • In 1 - In 4: Connected to Arduino UNO pins D4 - D7 respectively
  • BLUE wire - RED wire: Connected to corresponding wires of Stepper Motor 2

Documented Code

#include <AccelStepper.h>

// Define the pins for motor 1 
AccelStepper motor1(AccelStepper::HALF4WIRE, 8, 10, 9, 11);

// Define the pins for motor 2
AccelStepper motor2(AccelStepper::HALF4WIRE, 4, 6, 5, 7);

// Set initial rotation speed
const int rotationSpeed = 500; 

void setup() {
  // Set up the serial communication for Bluetooth
  Serial.begin(9600);

  motor1.setMaxSpeed(rotationSpeed);
  motor1.setAcceleration(500);
  motor1.setCurrentPosition(0);

  motor2.setMaxSpeed(rotationSpeed);
  motor2.setAcceleration(500);
  motor2.setCurrentPosition(0);
}

void loop() {
  // Check if data is available from the Bluetooth app
  if (Serial.available() > 0) {
    char command = Serial.read();

    // Write commands for the app
    switch (command) {
      case 'F':  // Start both motors rotating forward
        motor1.setSpeed(rotationSpeed);
        motor2.setSpeed(rotationSpeed);
        motor1.enableOutputs();
        motor2.enableOutputs();
        break;
      case 'B':  // Start both motors rotating backward
        motor1.setSpeed(-rotationSpeed);
        motor2.setSpeed(-rotationSpeed);
        motor1.enableOutputs();
        motor2.enableOutputs();
        break;
      case 'S':  // Stop and disconnect both motors
        motor1.setSpeed(0);       // Set speed to 0 to stop immediately
        motor2.setSpeed(0);       // Set speed to 0 to stop immediately
        motor1.disableOutputs();  // Disable outputs to disconnect motors
        motor2.disableOutputs();  // Disable outputs to disconnect motors
        break;
      default:
        // Ignore any other commands
        break;
    }
  }

  // Run motors
  motor1.runSpeed();
  motor2.runSpeed();
}

Filename: sketch.ino

Description: This code snippet is the main program for the Arduino UNO. It initializes two AccelStepper objects for controlling the stepper motors. The setup function configures the serial communication and sets the maximum speed and acceleration for both motors. The loop function listens for serial commands to control the motors' speed and direction.