Using the 28BYJ-48 Stepper Motor with a ULN2003 Driver and Arduino

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

ManufacturerULN2003
Part numberULN2003
Logic/IO voltage5 V
Supply voltage5–30 V (max)
Output current (per channel)500 mA max
Peak current (per channel)2 A max
PWM frequency guidanceN/A
Input logic thresholds0.8 V (low), 2.4 V (high)
Voltage drop / RDS(on) / saturation1.5 V max
Thermal limits70 °C max
PackageDIP-16
Notes / variantsCommonly 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:

  • Orange wire to OUT1
  • Yellow wire to OUT2
  • Pink wire to OUT3
  • Blue wire to OUT4

Next, connect the ULN2003 driver to the Arduino. The input pins on the driver correspond to four digital pins on the Arduino. For example:

  • IN1 to Pin 10
  • IN2 to Pin 11
  • IN3 to Pin 12
  • IN4 to Pin 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
6-The source code for stepper motor 28BYJ-48 with ULN2003 for Arduino
Language: C++
Copied!

Files📁

No files available.