# Stepper Motor Tutorial

## 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
• Jumper wires
• Arduino hardware and software

## Process

### Functioning of Stepper Motors

Stepper motors consist of multiple coils, and by transferring energy from coil to coil, phases are triggered which translate directly to steps being taken by the motor. There are two main types of stepper motors: unipolar and bipolar. Unipolar motors are simple to connect since the positive and negative ends of the circuit are specifically assigned to test leads that will not change as energy flows; however, a disadvantage to these motors is that there is available torque since only half of the coils of the motor are energized at once. On the other hand, bipolar motors use H-bridge circuitry to utilize alternating current rather than direct current. By using alternating current, bipolar motors are more efficient by energizing all of the coils simultaneously.

### Finding a Compatible Stepper Driver for the Stepper Motor

The datasheets of the stepper motor and stepper driver can both be found online simply through a search engine. These datasheets will provide information necessary to take into consideration when choosing a stepper driver to be compatible with a stepper motor. First, find the amps per phase (the maximum current that the motor coils can handle before overheating) and the resistance per phase of the stepper motor. Using Ohm's Law, V = IR, calculate the voltage rating of the motor. Since a constant-voltage driver will be used, the voltage of the stepper motor should match the voltage of the driver. From the datasheet of the driver, the maximum voltage that can flow through the driver and the maximum current that the driver can supply to the motor can be found. It is crucial to choose a stepper driver that is compatible with the stepper motor so that enough current is supplied to energize the coils of the motor yet does not overheat the system.

### 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)