Maker 101
Published © GPL3+

Multiple Stepper Motor Control (ULN2003 and 28BYJ-48)

Multiple Stepper Motor Control (ULN2003 and 28BYJ-48) 3 Different Controls With 2 Libraries

BeginnerProtip2 hours160
Multiple Stepper Motor Control (ULN2003 and 28BYJ-48)

Things used in this project

Hardware components

Electrolytic Capacitors Kit (10uF 16V)
×1
Multilayer Ceramic Capacitor Kit (100nF)
×1
JST-XH Connector Kit (XH-5A)
×1
2.54mm Male and Female Pin Header Kit
×1
5mm LED Light Emitting Diode
×1
Carbon Film Resistors (220 ohm)
×1
Screw Terminal Block Connector (5mm 2 Pin)
×1
28BYJ-48 ULN2003 5V Stepper Motor
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering Iron Kit

Story

Read more

Schematics

Schematic

Code

uln2003_simple_code.ino

Arduino
//Includes the Arduino Stepper Library
#include <Stepper.h>

// Defines the number of steps per rotation
const int stepsPerRevolution = 4076;

// Creates an instance of stepper class
// Pins entered in sequence IN1-IN3-IN2-IN4 for proper step sequence
Stepper leftStepper = Stepper(stepsPerRevolution, 2, 4, 3, 5);
Stepper rightStepper = Stepper(stepsPerRevolution, 6, 8, 7, 9);


void setup() {
    // Nothing to do (Stepper Library sets pins as outputs)
}

void loop() {
	// Rotate CW slowly at 5 RPM
	leftStepper.setSpeed(5);
  rightStepper.setSpeed(5);
	leftStepper.step(stepsPerRevolution);
  rightStepper.step(stepsPerRevolution);
	delay(1000);
	
	// Rotate CCW quickly at 10 RPM
	leftStepper.setSpeed(5);
  rightStepper.setSpeed(5);
	leftStepper.step(-stepsPerRevolution);
  rightStepper.step(-stepsPerRevolution);
	delay(1000);
}

uln2003_accelStepper_code.ino

Arduino
// Include the AccelStepper Library
#include <AccelStepper.h>

// Define step constant
#define MotorInterfaceType 4

// Creates an instance
// Pins entered in sequence IN1-IN3-IN2-IN4 for proper step sequence
AccelStepper leftStepper(MotorInterfaceType, 2, 4, 3, 5);
AccelStepper rightStepper(MotorInterfaceType, 6, 8, 7, 9);

void setup() {
	// set the maximum speed, acceleration factor,
	// initial speed and the target position
	leftStepper.setMaxSpeed(1000.0);
  rightStepper.setMaxSpeed(1000.0);
	leftStepper.setAcceleration(50.0);
  rightStepper.setAcceleration(50.0);
	leftStepper.setSpeed(200);
  rightStepper.setSpeed(200);
	leftStepper.moveTo(2038);
  rightStepper.moveTo(2038);
}

void loop() {
	// Change direction once the motor reaches target position
	if (leftStepper.distanceToGo() == 0) 
		leftStepper.moveTo(-leftStepper.currentPosition());

  if (rightStepper.distanceToGo() == 0) 
		rightStepper.moveTo(-rightStepper.currentPosition());

	// Move the motor one step
	leftStepper.run();
  rightStepper.run();
}

uln2003_accelStepper_2_code.ino

Arduino
// Include the AccelStepper Library
#include <AccelStepper.h>

// Define step constants
#define FULLSTEP 4
#define HALFSTEP 8

// Creates two instances
// Pins entered in sequence IN1-IN3-IN2-IN4 for proper step sequence
AccelStepper leftStepper(HALFSTEP, 2, 4, 3, 5);
AccelStepper rightStepper(FULLSTEP, 6, 8, 7, 9);

void setup() {
	// set the maximum speed, acceleration factor,
	// initial speed and the target position for motor 1
	leftStepper.setMaxSpeed(1000.0);
	leftStepper.setAcceleration(50.0);
	leftStepper.setSpeed(200);
	leftStepper.moveTo(2038);

	// set the same for motor 2
	rightStepper.setMaxSpeed(1000.0);
	rightStepper.setAcceleration(50.0);
	rightStepper.setSpeed(200);
	rightStepper.moveTo(-2038);
}

void loop() {
	// Change direction once the motor reaches target position
	if (leftStepper.distanceToGo() == 0) 
		leftStepper.moveTo(-leftStepper.currentPosition());
	if (rightStepper.distanceToGo() == 0) 
		rightStepper.moveTo(-rightStepper.currentPosition());

	// Move the motor one step
	leftStepper.run();
	rightStepper.run();
}

Credits

Maker 101

Maker 101

50 projects • 178 followers
Maker 101; Beginner and intermediate level Maker projects!

Comments