Introduction: Arduino + Stepper Motor(28BYJ-48) + Motor Driver(ULN2003AN)
In this instructable we are going to make this stepper motor work using Arduino.
Step 1: Connect SM to MD
Connect the stepper motor to the motor drivers.
Step 2: Create Some Jumper-to-DuPont Wires.
Solder them together, make sure they are not too short.
Step 3: Connect Ground (left) & Power (right).
Orient them so they fit snuggly.
Step 4: Connect Them to Arduino
5V & Ground.
Step 5: Make Some More Jumper-to-DuPont Wires!
Or just use a female to male dupont wire? But I didn't had any.
Step 6: Connect Them to the Motor Driver, in No Specific Order.
Step 7: Connect Them to Arduino.
IN1 - IN4 on the drivers should be connected to Arduino pins 9 to 12 in order.
IN1 - 9
IN2 - 10
etc.
Step 8: Flash the Arduino (Explained in Comments)
#define STEPPER_PIN_1 9
#define STEPPER_PIN_2 10 #define STEPPER_PIN_3 11 #define STEPPER_PIN_4 12
int step_number = 0; //current step out of 4
void setup() {
pinMode(STEPPER_PIN_1, OUTPUT);
pinMode(STEPPER_PIN_2, OUTPUT);
pinMode(STEPPER_PIN_3, OUTPUT);
pinMode(STEPPER_PIN_4, OUTPUT);
}void loop() {
OneStep(false); //false means the motor will go counter clockwise.
delay(2); //every 2ms the motor will make a step, 2ms is max speed for this motor.
}void OneStep(bool dir) {
if (dir) { //if going clockwise
switch (step_number) {
case 0:
digitalWrite(STEPPER_PIN_1, HIGH);
digitalWrite(STEPPER_PIN_2, LOW);
digitalWrite(STEPPER_PIN_3, LOW);
digitalWrite(STEPPER_PIN_4, LOW);
break;
case 1:
digitalWrite(STEPPER_PIN_1, LOW);
digitalWrite(STEPPER_PIN_2, HIGH);
digitalWrite(STEPPER_PIN_3, LOW);
digitalWrite(STEPPER_PIN_4, LOW);
break;
case 2:
digitalWrite(STEPPER_PIN_1, LOW);
digitalWrite(STEPPER_PIN_2, LOW);
digitalWrite(STEPPER_PIN_3, HIGH);
digitalWrite(STEPPER_PIN_4, LOW);
break;
case 3:
digitalWrite(STEPPER_PIN_1, LOW);
digitalWrite(STEPPER_PIN_2, LOW);
digitalWrite(STEPPER_PIN_3, LOW);
digitalWrite(STEPPER_PIN_4, HIGH);
break;
}
} else { //go anti clockwise
switch (step_number) {
case 0:
digitalWrite(STEPPER_PIN_1, LOW);
digitalWrite(STEPPER_PIN_2, LOW);
digitalWrite(STEPPER_PIN_3, LOW);
digitalWrite(STEPPER_PIN_4, HIGH);
break;
case 1:
digitalWrite(STEPPER_PIN_1, LOW);
digitalWrite(STEPPER_PIN_2, LOW);
digitalWrite(STEPPER_PIN_3, HIGH);
digitalWrite(STEPPER_PIN_4, LOW);
break;
case 2:
digitalWrite(STEPPER_PIN_1, LOW);
digitalWrite(STEPPER_PIN_2, HIGH);
digitalWrite(STEPPER_PIN_3, LOW);
digitalWrite(STEPPER_PIN_4, LOW);
break;
case 3:
digitalWrite(STEPPER_PIN_1, HIGH);
digitalWrite(STEPPER_PIN_2, LOW);
digitalWrite(STEPPER_PIN_3, LOW);
digitalWrite(STEPPER_PIN_4, LOW);
}
}
step_number++;
if (step_number > 3) {
step_number = 0;
}}



