Arduino UNO Controlled 28BYJ-48 Stepper Motor with ULN2003 Driver
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
This circuit controls a 28BYJ-48 stepper motor using an Arduino UNO and a ULN2003 driver. The Arduino UNO provides the control signals to the ULN2003 driver, which in turn drives the stepper motor. The motor will rotate in one direction for a specified number of steps, then reverse direction for the same number of steps.
Component List
Arduino UNO
- Description: A microcontroller board based on the ATmega328P.
- Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0
28BYJ-48 Stepper Motor
- Description: A small, inexpensive stepper motor commonly used in hobby projects.
- Pins: BLUE, PINK, YELLOW, ORANGE, RED
ULN2003
- Description: A Darlington transistor array used to drive the stepper motor.
- Pins: IN1, IN2, IN3, IN4, IN5, IN6, IN7, GND, +, COIL1, COIL2, COIL3, COIL4, COIL5
Wiring Details
Arduino UNO
- 5V connected to ULN2003 pin +
- GND connected to ULN2003 pin GND
- D7 connected to ULN2003 pin IN1
- D6 connected to ULN2003 pin IN2
- D5 connected to ULN2003 pin IN3
- D4 connected to ULN2003 pin IN4
28BYJ-48 Stepper Motor
- BLUE connected to ULN2003 pin COIL1
- PINK connected to ULN2003 pin COIL2
- YELLOW connected to ULN2003 pin COIL3
- ORANGE connected to ULN2003 pin COIL4
- RED connected to ULN2003 pin COIL5
ULN2003
- + connected to Arduino UNO pin 5V
- GND connected to Arduino UNO pin GND
- IN1 connected to Arduino UNO pin D7
- IN2 connected to Arduino UNO pin D6
- IN3 connected to Arduino UNO pin D5
- IN4 connected to Arduino UNO pin D4
- COIL1 connected to 28BYJ-48 Stepper Motor pin BLUE
- COIL2 connected to 28BYJ-48 Stepper Motor pin PINK
- COIL3 connected to 28BYJ-48 Stepper Motor pin YELLOW
- COIL4 connected to 28BYJ-48 Stepper Motor pin ORANGE
- COIL5 connected to 28BYJ-48 Stepper Motor pin RED
Code Documentation
/*
* Przykładowy program demonstujący działanie silnika krokowego.
* This code controls a 28BYJ-48 stepper motor using an Arduino UNO and a
* ULN2003 driver. The motor will rotate in one direction for a few steps,
* then reverse direction for the same number of steps.
*/
// Define the pins connected to the ULN2003 driver
#define IN1 7
#define IN2 6
#define IN3 5
#define IN4 4
// Number of steps per revolution for 28BYJ-48
const int stepsPerRevolution = 2048;
void setup() {
// Set the pins as outputs
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);
}
void loop() {
// Rotate the motor in one direction
for (int i = 0; i < stepsPerRevolution; i++) {
stepMotor(i % 4);
delay(2);
}
delay(1000);
// Rotate the motor in the opposite direction
for (int i = stepsPerRevolution; i > 0; i--) {
stepMotor(i % 4);
delay(2);
}
delay(1000);
}
void stepMotor(int step) {
switch (step) {
case 0:
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
break;
case 1:
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
break;
case 2:
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, HIGH);
digitalWrite(IN4, LOW);
break;
case 3:
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, HIGH);
break;
}
}
This code sets up the Arduino UNO to control the ULN2003 driver, which in turn drives the 28BYJ-48 stepper motor. The motor will rotate in one direction for a specified number of steps, then reverse direction for the same number of steps.