Arduino Nano - 28BYJ-48 Stepper Motor ULN2003 Driver
This tutorial instructs you how to use Arduino Nano to control 28BYJ-48 Stepper Motor using ULN2003 Driver. In detail, we will learn:
- How to connect Arduino Nano to 28BYJ-48 stepper motor via ULN2003 driver
- How to program Arduino Nano to control a single 28BYJ-48 stepper motor via ULN2003 driver
- How to program Arduino Nano to control multiple 28BYJ-48 stepper motors via ULN2003 drivers
Hardware Preparation
Or you can buy the following sensor kits:
1 | × | DIYables Sensor Kit (30 sensors/displays) | |
1 | × | DIYables Sensor Kit (18 sensors/displays) |
Additionally, some of these links are for products from our own brand, DIYables.
Overview of 28BYJ-48 Stepper Motor
Stepper motors are excellent for position control. They divide a complete revolution into a number of equal "steps". These motors are used in many devices, such as printers, 3D printers, CNC machines, and industrial automation.
One of the budget-friendly methods to gain knowledge about stepper motors is to utilize 28BYJ-48 stepper motors. These typically come with a ULN2003 based driver board, which makes them incredibly easy to use.
As indicated in the data sheet, the 28BYJ-48 motor operates in full-step mode with each step corresponding to an 11.25° rotation. Therefore, there are 32 steps per revolution (360°/11.25° = 32).
Furthermore, the motor has a 1/64 reduction gear set. This translates to 32 x 64 = 2048 steps. Each step is equivalent to 360°/2048 = 0.1758°.
Conclusion: If the motor is set to full-step mode, it will take 2048 steps for it to complete one revolution.
The 28BYJ-48 Stepper Motor using ULN2003 Driver Pinout
The 28BYJ-48 stepper motor has 5 pins. It is not necessary to be concerned with the specifics of these pins; they simply need to be connected to the ULN2003 motor driver connector.
Overview of ULN2003 Stepper Motor Driver
The ULN2003 is a widely used motor driver Module for stepper motors.
- It has four LEDs that demonstrate the activity of the four control input lines, which give a great visual effect when the motor is stepping.
- Additionally, it includes an ON/OFF jumper to separate power from the stepper motor.
ULN2003 Pinout
The ULN2003 module has 6 pins and a female connector:
- IN1 pin: this is used to drive the motor. It should be connected to an output pin on the Arduino Nano board.
- IN2 pin: this is used to drive the motor. It should be connected to an output pin on the Arduino Nano board.
- IN3 pin: this is used to drive the motor. It should be connected to an output pin on the Arduino Nano board.
- IN4 pin: this is used to drive the motor. It should be connected to an output pin on the Arduino Nano board.
- GND pin: this is the common ground pin. It must be connected to both the GNDs of the Arduino Nano board and the external power supply.
- VDD pin: this supplies power for the motor. It should be connected to the external power supply.
- Motor Connector: this is where the motor plugs into.
※ NOTE THAT:
- The voltage of the external power supply should be equal to the voltage of stepper motor. For example, if a stepper motor works with 12V DC, we need to use a 12V power supply. In the case of 28BYJ-48 stepper motor, it operates with 5V DC, so we will use a 5V power supply.
- However, even if the stepper motor requires a 5V power supply, please do NOT connect the VDD pin to the 5V pin on the Arduino Nano. Instead, connect it to an external 5V power supply, as the stepper motor draws too much power.
Wiring Diagram
This image is created using Fritzing. Click to enlarge image
It is not necessary to pay attention to the colour of the wires on the stepper motor. All that is required is to connect the male connector on the 28BYJ-48 stepper motor to the female connector on the ULN2003 driver.
How To Program to control a stepper motor
There are three ways to regulate a stepper motor:
- Full-step
- Half-step
- Micro-step
For basic applications, we can use the full-step approach. The specifics of the three methods will be outlined in the final section of this tutorial. Programming these techniques can be complex. Fortunately, there are many libraries that have done the work for us, so we just need to utilize them.
The Arduino IDE features a built-in Stepper library. However, we do not suggest you to utilize this library as:
- It is a blocking library, meaning it prevents the Arduino Nano from performing other tasks while controlling the stepper motor.
- It does not provide enough functions.
Instead, we suggest that you utilize the AccelStepper library. This library offers:
- Acceleration
- Deceleration
- Full-step and half-step driving
- Multiple simultaneous steppers, with independent concurrent stepping on each stepper
- Disadvantage: No micro-step driving support
Arduino Nano Code
Detailed Instructions
- Click to the Libraries icon on the left bar of the Arduino IDE.
- Search for “AccelStepper”, then locate the AccelStepper library created by Mike McCauley.
- Click the Install button to add the AccelStepper library.
- Copy the code above and open it with the Arduino IDE.
- Click the Upload button on the Arduino IDE to upload the code to the Arduino Nano.
- You should then see the motor rotating. It should make one revolution in a clockwise direction, followed by two revolutions in an anti-clockwise direction, and then two revolutions in a clockwise direction.
The procedure is carried out continuously.
- Check out the output in the Serial Monitor.
How to control a multiple 28BYJ-48 stepper motors
Let us discover how to manage two stepper motors separately yet simultaneously.
Wiring Diagram for two 28BYJ-48 stepper motors
This image is created using Fritzing. Click to enlarge image
Arduino Nano Code for two 28BYJ-48 stepper motors
Additional Knowledge
1. Stepper motor vibrates while moving
Do NOT be concerned if the stepper motor shakes while in motion. This is a characteristic of the stepper motor. We can lower the vibration by using the micro-stepping control technique.
Additionally, due to this feature, if managed correctly, the stepper motor can create music as if it were a musical instrument. An example of this can be found here on Hackster.io.
2. Method of controlling stepper motors
- Full-step: The unit of movement is one step, which is equal to the degree value specified in the stepper motor's datasheet or manual.
- Half-step: Splits each full step into two smaller steps. The unit of movement is half of the full step. This method allows the motor to move with double resolution.
- Micro-step: Divides each full step into many smaller steps. The unit of movement is a fraction of the full step. The fraction can be 1/4, 1/8, 1/16, 1/32 or even more. This method allows the motor to move with higher resolution. It also makes the motor move smoother at low speeds. The bigger the divisor, the higher the resolution and the smoother the motion.
If the motor's datasheet specifies 1.8 degree/step:
- Full-step: The motor will move in increments of 1.8 degrees per step, resulting in 200 steps per revolution.
- Half-step: The motor will move in increments of 0.9 degrees per step, resulting in 400 steps per revolution.
- Micro-step: The motor will move in increments of 0.45, 0.225, 1125, 0.05625 degrees per step, resulting in 800, 1600, 3200, 6400... steps per revolution.
The control method used in the code above was the full-step approach.
3. Resonance Issue
This is for advanced users. Beginners do not need to be concerned with it. It occurs in a range of speeds, where the step rate is equal to the motor's natural frequency. There could be a noticeable change in the sound made by the motor, as well as an increase in vibration. In practical applications, developers should take this into consideration.