Arduino Unipolar Stepper Motor Control

In the last Arduino project, I made a simple motor controller which controls the speed and direction of rotation of CD-ROM bipolar stepper motor. Now I’m going to show how to do the same thing with uinpolar stepper motor.
The stepper motor used in this example is 28BYJ-48 which usually comes with its driver board.

Related Projects:
Arduino Bipolar Stepper Motor Control
Stepper Motor Control with Arduino and Joystick

Basically there are two types of stepper motors: bipolar and unipolar. The bipolar stepper motor is a two-phase brushless motor which has two coils (windings), this motor has 4 wires (2 wires for each coil).
The other type is the unipolar stepper motor, it is 4-phase brushless motor which has 5 or 6 wires.

The popular controlling modes of of the stepper motor are: full step and half step. The full step can be divided into 2 types: one-phase and two-phase.

In full step one-phase mode the driver energizes one coil at a time. This type of controlling requires the least amount of power but provides the least torque.

In full step two-phase mode the driver energizes the two coils at the same time. This mode provides the highest torque but it requires twice as much power as one-phase mode.

Half step mode is a combination of the two full step modes (one-phase and two-phase). This mode increases accuracy by dividing each step by 2. it requires power in-between one-phase and two-phase modes, torque is also in-between.

There is another controlling type called microstepping, this type is more accurate than the half step mode, it requires two sinusoidal current sources with 90° shift.

In this example I’m going to use the full step two-phase mode for controlling the unipolar stepper motor.
Usually the unipolar stepper motor has 5 wires one for motor supply and the other for coils. This motor has 4 coils and they are connected as shown in the figure below:

Unipolar stepper motor coils

As shown in the above figure there are 4 coils: A, B, C and D. These coils has common point named in the figure Motor supply which is connected to positive terminal of power supply source. Other coil terminals are connected to a motor driver.

The unipolar stepper motor can be driven with L293D motor driver or ULN2003A Darlington transistor array IC. In this example I’m going to use the ULN2003A (or ULN2004) chip.

In the full step control mode always two windings are energized at the same time according to the following table where 1 means the coil is energized and 0 means not energized (both directions are shown):

Unipolar stepper motor two phase sequence

Hardware Required:

  • Arduino UNO board
  • 28BYJ-48 unipolar stepper motor (with driver board)
  • 10k ohm potentiometer
  • Pushbutton
  • 5V power source
  • Bread board
  • Jumper wires

Arduino 28-BYJ48 stepper motor controller

Arduino uinpolar stepper motor control circuit:
Example circuit diagram is shown below (all grounded terminals are connected together).

Arduino unipolar stepper motor control circuit

and the following image shows fritzing circuit:

Arduino 28-BYJ48 unipolar stepper motor control circuit

The stepper motor is connected to the ULN2003A board which is supplied with external power source of 5V. The control lines (IN1, IN2, IN3 and IN4) of this board are connected to the Arduino as follows:
IN1 to Arduino pin 11
IN2 to Arduino pin 10
IN3 to Arduino pin 9
IN4 to Arduino pin 8

The 10k ohm potentiometer is used to control the speed of the stepper motor, its output pin is connected to Arduino analog pin 0.

The push button which is connected to Arduino pin 4 is used to change the rotation direction of the stepper motor.

Arduino unipolar stepper motor control code:
In this example I used Arduino stepper motor library (built-in) which simplifies the code, it’s included in the code using the following line:

The stepper motor which I used in this project is 28BYJ-48, this motor equipped with speed reducer of 1/64. The internal motor has 32 steps per one revolution which means the external shaft has 2048 steps per one revolution (64 x 32). Number of steps is defined in the code as shown below:

and the connection of the control lines of the stepper motor are defined as:

Using the function stepper.step(direction_) the stepper motor moves according to the variable direction_, in this example this variable may be 1 or -1. If direction_ = 1 the motor will move in the first direction and if direction_ = -1 the motor will move in the other direction.

When ever the pushbutton is pressed, the variable direction_ will be inverted (1 or -1).

Rest of code is described through comments.

The following video shows a simple hardware circuit of the project:

1 thought on “Arduino Unipolar Stepper Motor Control”

Leave a Comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top