Tiva Lab 06: Stepper Motor Interface


  • Learn how to interface a stepper motor with a microcontroller
  • Learn how to drive a stepper motor
  • Learn how to calculate the number of steps for the stepper motor to rotate at a certain angular degree

Required Reading Materials

Background Information

In this Laboratory, you will write firmware for generating digital TTL signals that can be used to provide the stepping sequence for a four-phase unipolar stepper motor in full-step mode.

Stepper Motor: 28BYJ-48

stepper motor controller uln2003 s

The 28BYJ-48 is a 5-wire unipolar stepper motor that runs on 5 volts. The detailed specs of the 28BYJ-48 stepper motor as shown below:

Motor Type Unipolar stepper motor
Connection Type 5 wire connection (to the motor controller): Blue, Pink, Yellow, Orange, Red
Voltage 5 Volts DC
Number of Phases 4
Operating Frequency (PPS) 100Hz
Step Mode Half-Step Mode: 8 step control signal sequence (recommended)
Full-Step Mode: 4 step control signal sequence
Step Angle Half-Step Mode: 5.625º per step / 64 steps per one revolution of the internal motor shaft.
Full-Step Mode: 11.25º per step / 32 steps per one revolution of the internal motor shaft
Gear ratio The manufacturer specifies: 64:1
Experimental result: 63.68395:1
Full revolution = steps per motor rotation x gear ratio
For half-step: 64 steps per motor rotation x 63.68395 gear ratio ≒ 4076 steps per full revolution
Step Angle (1-2 phase) 5.625º / 64

Step Sequence

The 28BYJ-48 is a Unipolar Stepper Motor. It has 4 coils of wire that are powered in a sequence to make the magnetic motor shaft spin. When using the full-step method, 2 of the 4 coils are powered at each step. For the half-step mode, the first step is to power coil 1,  then coil 1 and 2 together, then coil 2 only, and so on. With 4 coils, the half-step mode has 8 different signals. The following table shows the steps for half and full-step mode.

WAVE DRIVE: 1-Phase at a Time (Full-Step)

Step 0 X      
Step 1   X    
Step 2     X  
Step 3       X

Simplest, but least used.

HALF STEP: 1 or 2 Phase at a Time (Half-Step)

Step 0 X      
Step 1 X X    
Step 2   X    
Step 3   X X  
Step 4     X  
Step 5     X X
Step 6       X
Step 7 X     X

Smallest step angle. Medium torque.

FULL STEP: 2 Phases at a Time (Full-Step)

Step 0 X X    
Step 1   X X  
Step 2     X X
Step 3 X     X

Strongest torque.




In this lab, you need to complete the firmware code to control a stepper motor.

Required Component List

Stepper Motor x 1
ULN2003 Stepper Motor Driver Module x 1
breadboard power s Breadboard Power Supply Module x 1
Power Adapter 9V/2A x 1
breadboard s Breadboard x 1

Circuit/Schematic Diagram

The stepper motor used in this lab is the 28BYJ-48, with gear reduction, hence provides relatively good torque but slow rotation. The ULN2003A is a Darlington high current transistor array used to drive the 5v stepper motor. The following diagrams are schematic of the internal coils of this stepper motor and how each coil connects to the ULN2003A for each Tiva LaunchPad board. These coils must be connected to the right output of the ULN2003A to ensure correct sequencing.


  1. Please create a new folder under the EE3450 folder, named it as Lab06_StepperMotor. Then start the Keil μVisio and create a new project, save the project inside the Lab06_StepperMotor folder.
  2. Copy-paste the following code to your main.c file.
  3. Modify the Setup_GPIO() function based on the Pin Configuration Table to configure the GPIO Pins..

Lab Experiments

Write a firmware code using FULL STEP (2-Phases at a Time) to control the stepper motor rotates 120 degrees from left to right by sending sequence data from an array, which stores full step encoded values. You have to calculate the steps for 120 degrees from the data table of the stepper motor at the top of this lab.

There are three ways to implement the stepper motor control:


  1. A 10° per step stepper motor is given 60 steps clockwise (CW) and 15 steps counter-clockwise (CCW). Assuming it started at 0°, calculate the final position in degree.