"Because the motor draws too much power, it is best to power it directly from an external 5V power supply rather than drawing that power from the Arduino."
The ULN2003 Driver Board:
This board can be used as a useful way to connect both the Arduino and power supply to the motors. There's Step Indicator LEDs which are useful for making sure that the motor is stepping as expected and an on/off jumper to stop power from going to the motor if necessary.
It is recommended to use a separate 5V power supply to power the stepper motors, as directly powering it through the Arduino can cause electrical noise on the power supply lines.
Above is a diagram which shows how they should be attached:
Using a seperate 5V power supply connect this to the driver board, make sure that the ground from the external power supply gets connected to the Arduino's ground.
Connect the Driver board to the Arduino Digital pins:
IN1 - 8
IN2 - 9
IN3 - 10
IN4 - 11
Connect the motor cable to the driver board.
"The stepper library takes care of the stepping sequence and makes it straight forward to control a wide variety of stepper motors, both unipolar and bipolar."
Below is some example code from Last Minute Engineers which makes the stepper motor turn clockwise slowly then counter clockwise quickly.
//Includes the Arduino Stepper Library
#include <Stepper.h>
// Defines the number of steps per rotation, holds the number of steps that the motor takes to complete a "revolution"
const int stepsPerRevolution = 2038;
// Creates an instance of stepper class
// Pins entered in sequence IN1-IN3-IN2-IN4 for proper step sequence
Stepper myStepper = Stepper(stepsPerRevolution, 8, 10, 9, 11);
void loop() {
// Rotate CW slowly
myStepper.setSpeed(100); //sets the speed that I'd want the stepper motor to move at.
myStepper.step(stepsPerRevolution); // this then tells the stepper how many times to rotate.
delay(1000); // pauses the stepper
// Rotate CCW quickly
myStepper.setSpeed(700);
myStepper.step(-stepsPerRevolution); //a negative number reverses the spinning direction of the motor.
delay(1000);
}
In order to use multiple steppers, you will need to use the AccelStepper Library which will allow for acceleration/deceleration, half-step driving, multiple simultaneous steppers, with independent stepping.
Comments