28BYJ-48 & ULN2003 – Stepper Motor Control

In this post we will go over how to use the 28byj-48 stepper motor with the ULN2003 motor driver. We’ll focus on basics, module pins, how to connect to Arduino, programming in Arduino IDE, and testing.

What is a Stepper Motor?

Stepper motors are brushless DC electric motors that rotate its shaft in discrete steps of equal angular rotation. This is possible due to the fact that the motor has coils in groups and can we to energize them in a specific sequence to get one step (i.e. an incremental rotational step). This very nature of stepper motors allow us to move a specific number of steps without having a position/displacement sensor, while maintaining good accuracy on the position and speed of rotation of the motor.

28BYJ-48 Stepper Motor

The 28BYJ-48 stepper motor is a great stepper motor for a wide range of applications. It’s also a great motor for anyone looking to learn about stepper motors.

Rated Voltage: 5V DC

Gear Ratio: 64:1

Net steps per revolution: 2048 (~0.1758deg/step)
*Motor has 32 steps/revolution, and the gear ratio is 64:1, resulting in a net steps/revolution of 32*64=2048.

Coil Type: Unipolar

ULN2003 Motor Controller

The ULN2003 motor controller is used to interface your stepper motor (in this case the 28BYJ-48) and your microcontroller (in this case an Arduino UNO). The motor controller accepts four digital inputs from the microcontroller (IN1 – IN4) and the 5 cables coming from the 28BYJ-48 stepper motor. There is also the power input, which can be set to 5V or 12V. For the specific motor in this example we would go with 5V. The motor controller also has 4 step indicator LEDs so you can see the state of the coils of the motor as it rotates. When running fast it can be hard to see.

Connecting ULN2003, 28BYJ-48, and Arduino UNO

ULN2003 – IN1 through IN 4: Used to drive motor phases. Connect to Arduino UNO digital input/output pins 8, 9, 10, and 11.
ULN2003 Power In: Connect to 5V and ground
ULN2003 Motor Pins: Connect the motor cables. The 28BYJ-48 normally comes with a connector that matches the ULN2003 connection terminal. They only go in on a specific orientation, so it’s hard to make a mistake.

ULN2003 / 28BYJI Examples

List of Examples

  • Required Arduino Libraries
  • Example 1 – Move from A to B by a specific number of steps with specific speed and acceleration
  • Example 2 – Human input control (via rotary encoder)

Required Arduino Libraries

To complete the examples below you will need to install the AccelStepper Arduino library (written by Mike McCauley). To install it, open Arduino IDE, go to the top menu, click on “Sketch”, then “Include Library”, “Manage Libraries…”. Then type “AccelStepper”, then click install on the row for the AccelStepper library.

Example 1 – Move from A to B by a specific number of steps

In this example we will define the speed and acceleration at which we want the stepper motor to rotate and then make it rotate by a specified number of steps, stop, then rotate in the opposite direction in a specified number of steps. Specifically, we will do 3 rotations in one direction (meaning total steps will be the steps per revolution multiplied by 3 revolutions), stop and complete 3 rotations in the opposite direction.

Example 2 – Move the stepper motor by controlling with a rotary encoder

As the example title says, in this example we will control the rotation of a stepper motor using a rotary encoder. For details on how to use a rotary encoder, please take a look at my earlier post.

Components used in this example

*As an Amazon & Ebay Associate I earn from qualifying purchases.

ComponentLink
Arduino UNOhttps://amzn.to/3uYVAMC
https://ebay.us/veZdKX
Stepper Motor (28BYJ-48) with motor controller (ULN2003)https://amzn.to/3kX6JKD
https://ebay.us/hOrkrQ

6 Replies to “28BYJ-48 & ULN2003 – Stepper Motor Control”

  1. I’m often to blogging and i really appreciate your content. The article has actually peaks my interest. I’m going to bookmark your web site and maintain checking for brand spanking new information.

Leave a Reply

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