Using the 28BYJ-48 Stepper Motor with a ULN2003 Driver and Arduino
In this tutorial, we will learn how to control a 28BYJ-48 stepper motor using a ULN2003 driver with an Arduino. This setup allows for precise control of the motor's position and speed. By the end of this project, you will be able to rotate the motor in both directions and control its steps effectively.
We will use the 28BYJ-48 stepper motor, which is a popular choice for various robotics and automation projects due to its low cost and ease of use. The ULN2003 driver board interfaces the stepper motor with the Arduino, allowing us to send step signals that control the motor's movement. This tutorial will guide you through the necessary wiring and code to get your motor spinning.
For further clarification, please refer to the video associated with this tutorial (in video at 0:45).
Hardware Explained
The key components of this project include the 28BYJ-48 stepper motor and the ULN2003 driver board. The stepper motor consists of several coils that can be energized in a specific sequence to create rotation. The ULN2003 driver acts as a switch, allowing the Arduino to control the power delivered to each coil.
The ULN2003 driver uses a Darlington transistor array to handle the higher current required by the stepper motor. When a pin from the Arduino outputs a HIGH signal, it allows current to flow to the corresponding coil in the motor, causing it to move. This enables precise control over the rotation angle and speed of the motor.
Datasheet Details
| Manufacturer | ULN2003 |
|---|---|
| Part number | ULN2003 |
| Logic/IO voltage | 5 V |
| Supply voltage | 5–30 V (max) |
| Output current (per channel) | 500 mA max |
| Peak current (per channel) | 2 A max |
| PWM frequency guidance | N/A |
| Input logic thresholds | 0.8 V (low), 2.4 V (high) |
| Voltage drop / RDS(on) / saturation | 1.5 V max |
| Thermal limits | 70 °C max |
| Package | DIP-16 |
| Notes / variants | Commonly used with 5V stepper motors. |
- Ensure the driver can handle the current requirements of your motor.
- Use heat sinks if necessary to manage thermal limits.
- Check that all connections are secure to avoid floating inputs.
- Test the motor by running simple step sequences before integrating into larger projects.
- Make sure to power the motor with an adequate supply voltage.
Wiring Instructions
To wire the 28BYJ-48 stepper motor to the ULN2003 driver and Arduino, follow these steps:
First, connect the motor to the ULN2003 driver. The motor has four wires, typically color-coded as orange, yellow, pink, and blue. Connect these wires to the corresponding output pins on the ULN2003 driver. The connections are as follows:
Orangewire toOUT1Yellowwire toOUT2Pinkwire toOUT3Bluewire toOUT4
Next, connect the ULN2003 driver to the Arduino. The input pins on the driver correspond to four digital pins on the Arduino. For example:
IN1toPin 10IN2toPin 11IN3toPin 12IN4toPin 13
Finally, connect the power and ground pins of the ULN2003 driver to the Arduino. Connect the VCC pin to the Arduino's 5V output and the GND pin to the Arduino's ground. Ensure that all connections are secure before powering up the system.
Code Examples & Walkthrough
In the setup section of the Arduino code, we define the pins connected to the ULN2003 driver:
int Pin1 = 10;
int Pin2 = 11;
int Pin3 = 12;
int Pin4 = 13;
Here, we declare four integer variables: Pin1, Pin2, Pin3, and Pin4, which correspond to the digital pins on the Arduino. These pins will control the stepper motor's movement.
In the setup() function, we configure these pins as outputs:
void setup() {
pinMode(Pin1, OUTPUT);
pinMode(Pin2, OUTPUT);
pinMode(Pin3, OUTPUT);
pinMode(Pin4, OUTPUT);
}
This setup ensures that the Arduino can send signals to the ULN2003 driver to control the motor. The pinMode function sets each pin to OUTPUT mode, enabling them to send signals.
Finally, in the main loop, we create a switch case to control the motor's steps based on the variable _step:
switch(_step){
case 0:
digitalWrite(Pin1, LOW);
digitalWrite(Pin2, LOW);
digitalWrite(Pin3, LOW);
digitalWrite(Pin4, HIGH);
break;
// Additional cases follow
}
In this excerpt, we use digitalWrite to send HIGH or LOW signals to each pin based on the current _step. This controls which coils are energized, allowing the motor to rotate. The full code that integrates these snippets will be loaded below the article.
Demonstration / What to Expect
Once everything is wired correctly and the code is uploaded, the stepper motor should rotate in response to the signals from the Arduino. You can test the motor by modifying the delay in the loop or changing the steps to see how it reacts. Be aware that if the motor is not powered correctly, it may not move or could behave erratically.
Chapters
- Introduction - 0:00
- Hardware Explained - 1:30
- Wiring Instructions - 3:15
- Code Examples & Walkthrough - 5:00
- Demonstration / What to Expect - 7:45
// Original source is http://www.geeetech.com/wiki/index.php/Stepper_Motor_5V_4-Phase_5-Wire_%26_ULN2003_Driver_Board_for_Arduino
// Update by Ahmad Shamshiri for RoboJax.com
// Published on March 27, 2017 in Ajax, ON, Canada.
/*
*
Need wiring diagram from this code: https://youtu.be/0glBk917HPg
Purchase My Arduino course on Udemy.com http://robojax.com/L/?id=62
*
* Get this code and other Arduino codes from RoboJax.com
Learn Arduino step by step in a structured course with all material, wiring diagrams, and libraries
all in one place. Purchase My course on Udemy.com http://robojax.com/L/?id=62
If you found this tutorial helpful, please support me so I can continue creating
content like this.
or make a donation using PayPal http://robojax.com/L/?id=64
* * This code is "AS IS" without warranty or liability. Free to be used as long as you keep this note intact.*
* This code has been downloaded from RoboJax.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
int Pin1 = 10;
int Pin2 = 11;
int Pin3 = 12;
int Pin4 = 13;
int _step = 0;
boolean dir = true;// false=clockwise, true=counter clockwise
int count=0;
void setup()
{
pinMode(Pin1, OUTPUT);
pinMode(Pin2, OUTPUT);
pinMode(Pin3, OUTPUT);
pinMode(Pin4, OUTPUT);
}
void loop()
{
switch(_step){
case 0:
digitalWrite(Pin1, LOW);
digitalWrite(Pin2, LOW);
digitalWrite(Pin3, LOW);
digitalWrite(Pin4, HIGH);
break;
case 1:
digitalWrite(Pin1, LOW);
digitalWrite(Pin2, LOW);
digitalWrite(Pin3, HIGH);
digitalWrite(Pin4, HIGH);
break;
case 2:
digitalWrite(Pin1, LOW);
digitalWrite(Pin2, LOW);
digitalWrite(Pin3, HIGH);
digitalWrite(Pin4, LOW);
break;
case 3:
digitalWrite(Pin1, LOW);
digitalWrite(Pin2, HIGH);
digitalWrite(Pin3, HIGH);
digitalWrite(Pin4, LOW);
break;
case 4:
digitalWrite(Pin1, LOW);
digitalWrite(Pin2, HIGH);
digitalWrite(Pin3, LOW);
digitalWrite(Pin4, LOW);
break;
case 5:
digitalWrite(Pin1, HIGH);
digitalWrite(Pin2, HIGH);
digitalWrite(Pin3, LOW);
digitalWrite(Pin4, LOW);
break;
case 6:
digitalWrite(Pin1, HIGH);
digitalWrite(Pin2, LOW);
digitalWrite(Pin3, LOW);
digitalWrite(Pin4, LOW);
break;
case 7:
digitalWrite(Pin1, HIGH);
digitalWrite(Pin2, LOW);
digitalWrite(Pin3, LOW);
digitalWrite(Pin4, HIGH);
break;
default:
digitalWrite(Pin1, LOW);
digitalWrite(Pin2, LOW);
digitalWrite(Pin3, LOW);
digitalWrite(Pin4, LOW);
break;
}
if(dir){
_step++;
}else{
_step--;
}
if(_step>7){
_step=0;
}
if(_step<0){
_step=7;
}
delay(1);
}
Things you might need
-
AliExpressPurchase 5 pcs 28BYJ-48 stepper motors from AliExpresss.click.aliexpress.com
-
AliExpress
Resources & references
-
ExternalPurchase 5 pcs 28BYJ-48 stepper motors from AliExpresss.click.aliexpress.com
-
External
-
External
-
External
-
External
-
External
-
External
-
External
-
External
Files📁
No files available.