Interfacing Stepper Motor to Arduino

john September 28, 2017 No Comments

Arduino Stepper Motor Interfacing Using Darlington IC UL2003A

In this article, we are publishing a project which explains different aspects of interfacing a Stepper Motor with Arduino. Stepper motor is a specially designed DC motor which comes with advantages of both a servo motor and a normal dc motor. Compared to a normal Dc motor, the maximum rpm a stepper motor can produce is very low. But they have the advantage that they can be positioned accurately. Unlike servo motor, stepper motor can also be rotated continuously. On the basis of the winding arrangement inside, the stepper motor can be categorized into unipolar and bipolar. The stepper motor we are using here is a unipolar stepper motor named 28BYJ-48. After going through the project you can run or turn the motor to desired direction.

Let’s begin our tutorial and learn how to interface a stepper motor to Arduino.

Objectives of the Project

  • Understanding the basic working of stepper motor.
  • Interfacing of stepper motor with Arduino.
  • Generating code for turning motor to a desired direction.
  • Using a simple Arduino library for stepper motor interfacing.

Let’s begin to build our project!

Components Used

ComponentSpecificationQuantity
ArduinoUno1
Stepper Motor28BYJ-481
Darlington Pair TransistorULN2003A1
Resistors470 Ohms4
LED4

Arduino Stepper Motor Interfacing – Circuit Diagram

Arduino Stepper Motor Interfacing - Circuit Diagram

Arduino Stepper Motor Interfacing – Circuit Diagram

 

Assemble the circuit as shown in the diagram. Components required and connections are explained below

Stepper Motor 28BYJ-48

As mentioned earlier stepper motors are classified into unipolar and bipolar stepper motors according to their winding arrangement. 28BYJ-48 is a unipolar stepper motor with both windings center tapped and connected to the common pin of the ULN2003A. As per the circuit remaining four ends of the windings are connected to the output pins of a Darlington IC (ULN2003A). ULN2003 is a monolithic Darlington IC consists of seven NPN Darlington transistor pairs with high voltage and current capability. It consists of common cathode clamp diodes for each NPN Darlington pair, which makes this driver IC useful for switching inductive loads. Darlington IC is used here as the stepper motor driver for Arduino. Since 28BYJ works at 5V, we connect the com pin of ULN2003A to 5V pin of Arduino.

A Stepper motor can be operated in half step mode or full step mode. Here the code is written for it to work in full step mode. The library file attached with this article includes a provision for running the motor in half step mode as well. While working in half step mode the step-angle of the motor will be reduced to half the angle in full mode. In full step mode two coils are energized at a time. The speed of rotation of the motor can be controlled by altering the delay that is applied before energizing the next two coils. The maximum RPM that a 28BYJ-48 can generate is 15 rpm.

Let’s explain the coding part.

The Program/Code

Download Arduino Stepper Motor – Program

Download Library for Arduino Stepper Motor

The important aspects and subroutines of the program are explained below.

At the beginning of the program, four pre-processors are defined which mention the Arduino pins which are used for interfacing. Next is the use of constants in the program. The first 3 constants are for applying delay in between two consecutive coil energizing. Next two boolean constants are used for determining direction. At the “setup()” function, the Arduino pins that are used are configured as output pins. A function named “motoInput()” is used for energizing coils by giving ‘1’ to the specified coil which is to be energized and ‘0’ to the remaining coils which are not to be energized. Since we intend to run it in full step mode, we will energize two coils at a time. This can be seen in the function named “turnStepper()”.

“turnStepper()” is a function for turning the motor to a desired direction in a particular angle. The angle, direction of rotation and rpm of the motor can be given as parameters. “runStepper()” is function similar to “turnStepper()”. The only difference is that it is used of running the motor a particular number of rotation in a desired direction and rpm.

Examples on how to use these functions are written in the “loop()” function.

A simple library for unipolar stepper motor 28BYJ-48 is also attached with this article. Using library will make your program appear simpler. Few examples are also included in it, which will show how to use it properly.

Leave a Reply

Your email address will not be published. Required fields are marked *