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
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.