Difference between revisions of "Stepper Motor Tutorial"

From ESE205 Wiki
Jump to navigation Jump to search
 
(5 intermediate revisions by 2 users not shown)
Line 3: Line 3:
 
== Overview ==
 
== 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.
 
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.
 +
'''This tutorial is for the 28BYJ-48 Stepper Motor and ULN2003A Motor Driver.'''
  
 
== Materials/Prerequisites ==
 
== Materials/Prerequisites ==
*Stepper motor
+
*28BYJ-48 Stepper motor
*Stepper driver
+
*ULN2003A Stepper driver
*Breadboard
 
 
*Jumper wires
 
*Jumper wires
*Arduino hardware and software
+
*Arduino UNO hardware and software
  
 
== Process ==
 
== Process ==
Line 24: Line 24:
  
 
3. Connect negative wire of stepper driver to ground (GND) of Arduino and positive wire of stepper drive to 5V power source of Arduino.
 
3. Connect negative wire of stepper driver to ground (GND) of Arduino and positive wire of stepper drive to 5V power source of Arduino.
 +
 +
 +
[[File:StepperMotorFritzing.png | thumb | Diagram of stepper motor and motor driver connected to Arduino Uno]]
  
 
=== Code ===
 
=== Code ===
Line 38: Line 41:
 
'''2. In the setup of the code,  use the following syntax to guide the pins to be set to provide an output.'''
 
'''2. In the setup of the code,  use the following syntax to guide the pins to be set to provide an output.'''
  
void setup()
+
void setup() {
{
 
 
  pinMode(Pin0, OUTPUT);
 
  pinMode(Pin0, OUTPUT);
 
  pinMode(Pin1, OUTPUT);
 
  pinMode(Pin1, OUTPUT);
Line 55: Line 57:
 
  digitalWrite(Pin3, HIGH);
 
  digitalWrite(Pin3, HIGH);
 
  break;
 
  break;
 
 
  case 1:
 
  case 1:
 
  digitalWrite(Pin0, LOW);
 
  digitalWrite(Pin0, LOW);
Line 62: Line 63:
 
  digitalWrite(Pin3, HIGH);
 
  digitalWrite(Pin3, HIGH);
 
  break;
 
  break;
 
 
  case 2:
 
  case 2:
 
  digitalWrite(Pin0, LOW);
 
  digitalWrite(Pin0, LOW);
Line 69: Line 69:
 
  digitalWrite(Pin3, LOW);
 
  digitalWrite(Pin3, LOW);
 
  break;
 
  break;
 
 
  case 3:
 
  case 3:
 
  digitalWrite(Pin0, LOW);
 
  digitalWrite(Pin0, LOW);
Line 76: Line 75:
 
  digitalWrite(Pin3, LOW);
 
  digitalWrite(Pin3, LOW);
 
  break;
 
  break;
 
 
  case 4:
 
  case 4:
 
  digitalWrite(Pin0, LOW);
 
  digitalWrite(Pin0, LOW);
Line 83: Line 81:
 
  digitalWrite(Pin3, LOW);
 
  digitalWrite(Pin3, LOW);
 
  break;
 
  break;
 
 
  case 5:
 
  case 5:
 
 
  digitalWrite(Pin0, HIGH);
 
  digitalWrite(Pin0, HIGH);
 
  digitalWrite(Pin1, HIGH);
 
  digitalWrite(Pin1, HIGH);
Line 91: Line 87:
 
  digitalWrite(Pin3, LOW);
 
  digitalWrite(Pin3, LOW);
 
  break;
 
  break;
 
 
  case 6:
 
  case 6:
 
  digitalWrite(Pin0, HIGH);
 
  digitalWrite(Pin0, HIGH);
Line 98: Line 93:
 
  digitalWrite(Pin3, LOW);
 
  digitalWrite(Pin3, LOW);
 
  break;
 
  break;
 
 
  case 7:
 
  case 7:
 
  digitalWrite(Pin0, HIGH);
 
  digitalWrite(Pin0, HIGH);
Line 144: Line 138:
  
 
[https://learn.adafruit.com/all-about-stepper-motors/what-is-a-stepper-motor All About Stepper Motors]
 
[https://learn.adafruit.com/all-about-stepper-motors/what-is-a-stepper-motor All About Stepper Motors]
 +
 +
[http://eeshop.unl.edu/pdf/Stepper+Driver.pdf Stepper motor 28BYJ-48 Datasheet]

Latest revision as of 17:34, 18 April 2019

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. This tutorial is for the 28BYJ-48 Stepper Motor and ULN2003A Motor Driver.

Materials/Prerequisites

  • 28BYJ-48 Stepper motor
  • ULN2003A Stepper driver
  • Jumper wires
  • Arduino UNO 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.


Diagram of stepper motor and motor driver connected to Arduino Uno

Code

1. Initialize the pins of the stepper motor to pins on the board. For this example code, we assigned the pins to 8, 9, 10, and 11, but they can be assigned to whichever pins are desired. Create variables that will record the position of the motor, the number of steps taken, and the direction in which the motor should turn.

int Pin0 = 8; int Pin1 = 9; int Pin2 = 10; int Pin3 = 11; int _step = 0; int current_steps=0; boolean dir = true;

2. In the setup of the code, use the following syntax to guide the pins to be set to provide an output.

void setup() {

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

}

3. In the loop of the code, declare each possible case in which the motor can take steps. Since there are 4 pins and we are using the digitalWrite function that sets a pin to either high or low, there are 8 possible cases, as well as a default case which, in this sample code, sets each pin to low.

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;
}

4. This portion of the loop tells directs the stepper motor to either take a step in the counterclockwise direction or clockwise direction. The number of steps is recorded and resets if it reaches its boundary conditions.

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

Stepper motor 28BYJ-48 Datasheet