Stepper Motor Tutorial

From ESE205 Wiki
Jump to navigation Jump to search

Overview

A stepper motor is a DC motor that is used for making precise adjustments in position by taking discrete steps. There are many types of stepper motors that are used for different functions that vary in motor size, step count, gearing, shaft style, wiring, coils, and phases.

Materials/Prerequisites

  • Stepper motor
  • Stepper driver
  • Breadboard
  • Jumper wires
  • Arduino hardware and software

Process

Connecting Stepper Motor to Arduino

1. Connect stepper motor and stepper driver by connecting the white plug of the motor into the white opening of the driver.

2. Connect wires from IN1, IN2,IN3, and IN4 of stepper driver, and connect to pins 8, 9, 10, and 11 respectively.

3. Connect negative wire of stepper driver to ground (GND) of Arduino and positive wire of stepper drive to 5V power source of Arduino.

Code

int Pin0 = 8;

int Pin1 = 9;

int Pin2 = 10;

int Pin3 = 11;

int _step = 0;

int current_steps=0;

boolean dir = true;// gre

void setup()


pinMode(Pin0, OUTPUT);
pinMode(Pin1, OUTPUT);
pinMode(Pin2, OUTPUT);
pinMode(Pin3, OUTPUT);


void loop()

{

switch(_step){
case 0:
digitalWrite(Pin0, LOW);
digitalWrite(Pin1, LOW);
digitalWrite(Pin2, LOW);
digitalWrite(Pin3, HIGH);
break;
case 1:
digitalWrite(Pin0, LOW);
digitalWrite(Pin1, LOW);
digitalWrite(Pin2, HIGH);
digitalWrite(Pin3, HIGH);
break;
case 2:
digitalWrite(Pin0, LOW);
digitalWrite(Pin1, LOW);
digitalWrite(Pin2, HIGH);
digitalWrite(Pin3, LOW);
break;
case 3:
digitalWrite(Pin0, LOW);
digitalWrite(Pin1, HIGH);
digitalWrite(Pin2, HIGH);
digitalWrite(Pin3, LOW);
break;
case 4:
digitalWrite(Pin0, LOW);
digitalWrite(Pin1, HIGH);
digitalWrite(Pin2, LOW);
digitalWrite(Pin3, LOW);
break;
case 5:
digitalWrite(Pin0, HIGH);
digitalWrite(Pin1, HIGH);
digitalWrite(Pin2, LOW);
digitalWrite(Pin3, LOW);
break;
case 6:
digitalWrite(Pin0, HIGH);
digitalWrite(Pin1, LOW);
digitalWrite(Pin2, LOW);
digitalWrite(Pin3, LOW);
break;
case 7:
digitalWrite(Pin0, HIGH);
digitalWrite(Pin1, LOW);
digitalWrite(Pin2, LOW);
digitalWrite(Pin3, HIGH);
break;
default:
digitalWrite(Pin0, LOW);
digitalWrite(Pin1, LOW);
digitalWrite(Pin2, LOW);
digitalWrite(Pin3, LOW);
break;
}
if(dir){
_step++;
}else{
_step--;
}
if(_step>7){
_step=0;
}
if(_step<0){
_step=7;
}
delay(1);

}

Authors

Elizabeth Saliba

Liza Kaniewski

Michael Williams (TA)

Link to Project Page

Smarter_Blinds

External References

Adafruit Stepper Motor

Stepper Motor Datasheet

All About Stepper Motors