Introduction
In this tutorial we will see how to connect the stepper motor with an Arduino board, you will also find a programming code for your first tests. So the Stepper motors are commonly used in a variety of applications such as robotics, CNC machines, and 3D printers. Arduino is an open-source electronics platform based on easy-to-use hardware and software. In this tutorial, we will learn how to connect a stepper motor to Arduino.
Hardware Required
You will require the following Hardware Components for interfacing the Stepper Motor with Arduino.
Components | # | Buy From Amazon |
---|---|---|
Arduino UNO | 1 | Buy Now |
Stepper Motor (28BYJ-48) 5v | 1 | Buy Now |
H bridge L293D | 1 | Buy Now |
2.1mm Jack Screw Terminal | 1 | Buy Now |
9v DC Adapter (Optional) | 1 | Buy Now |
Jumper Wires | Few | Buy Now |
Breadboard | 1 | Buy Now |
What is Stepper Motor?
A stepper motor is an electromechanical device that converts electrical pulses into precise mechanical motion. Stepper motors are commonly used in applications where precise positioning and control is required.
This example is intended to use bipolar permanent magnet motors since these are the most common in small electronics projects.
In this case, we will use the 5v – 28BYJ-48 stepper motor, which is of the unipolar type. However, by using only 4 of its terminals and omitting the use of one of them, it can function as bipolar.
A bipolar motor has 2 coils, and 2 leads/terminals for each. Due to the configuration of the coils, current can flow in both directions, so a power stage is required to allow this. We will use the L293D H bridge.
Specifications
1. Voltage Rating: 3.2V
2. Current Rating: 2.8A
3. Holding Torque: 270 oz. in
4. Step Angle : 1.8 deg.
5. Steps Per Revolution: 200
6. No. of Phases: 4
7. Motor Length: 3.1 inches
8. No. of Leads: 4
9 Inductance Per Phase: 3.6mH
Features
- Precise control and positioning
- Low power consumption
- High torque at low speeds
- The reversible direction of rotation
Pinout of Stepper Motor
Pin Configuration of Motor
Pin Name | Wire Color | Description |
---|---|---|
Coil 1 | Orange | This Motor has a total of four coils. One end of all the coils are connected to +5V (red) wire and the other end of each coil is pulled out as wire colors Orange, Pink, Yellow, and Blue respectively |
Coil 2 | Pink | |
Coil 3 | Yellow | |
Coil 4 | Blue | |
+5V | Red | This Motor has a total of four coils. One end of all the coils are connected to +5V (red) wire and the other end of each coil is pulled out as wire colors Orange, Pink, Yellow and Blue respectively |
Pinout of H-bridge
Pin Configuration of H-bridge
Pin Name | Description |
Enable 1,2 | This pin enables the input pin Input 1(2) and Input 2(7) |
Input 1 | Directly controls the Output 1 pin. Controlled by digital circuits |
Output 1 | Connected to one end of Motor 1 |
Ground | Ground pins are connected to ground of circuit (0V) |
Ground | Ground pins are connected to ground of circuit (0V) |
Output 2 | Connected to another end of Motor 1 |
Input 2 | Directly controls the Output 2 pin. Controlled by digital circuits |
Vcc2 (Vs) | Connected to Voltage pin for running motors (4.5V to 36V) |
Enable 3,4 | This pin enables the input pin Input 3(10) and Input 4(15) |
Input 3 | Directly controls the Output 3 pin. Controlled by digital circuits |
Output 3 | Connected to one end of Motor 2 |
Ground | Ground pins are connected to ground of circuit (0V) |
Ground | Ground pins are connected to ground of circuit (0V) |
Output 4 | Connected to another end of Motor 2 |
Input 4 | Directly controls the Output 4 pin. Controlled by digital circuits |
Vcc2 (Vss) | Connected to +5V to enable IC function |
Working Explanation
A stepper motor is an electromechanical device that converts electrical pulses into mechanical movement. Stepper motors have multiple coils that are energized in a specific sequence to rotate the motor shaft. The L293D is a dual H-bridge motor driver that can be used to control the direction and speed of a stepper motor.
To connect a stepper motor to Arduino, we need to first identify the pins of the stepper motor. The 28BYJ-48 stepper motor has 4 coils and 5 wires. The wires are color-coded and should be connected to the L293D driver as follows:
- Connect the red wire to Vcc (5V).
- Connect the brown wire to GND.
- Connect the orange wire to Pin 8.
- Connect the yellow wire to Pin 9.
- Connect the pink wire to Pin 10.
Next, connect the L293D driver to Arduino. Connect the following pins:
- Pin 2 to Pin 7 of L293D (Input 1)
- Pin 3 to Pin 6 of L293D (Input 2)
- Pin 4 to Pin 2 of L293D (Input 3)
- Pin 5 to Pin 15 of L293D (Input 4)
Finally, connect a 9V battery or power supply to the L293D driver to power the stepper motor.
Circuit Diagram
The following circuit shows you the connection of the Stepper Motor with Arduino Please make the connection carefully
Installing Arduino IDE Software
First, you will require to Download the updated version of Arduino IDE Software and Install it on your PC or laptop. if you Learn How to install the Arduino step-by-step guide then click on how to install Arduino Button given Blow
Installing Libraries
Now when you are Ready to upload the code, to the Arduino Board you will need first to add the Following Libraries in Arduino, If you Learn How to add the library in the Arduino step-by-step guide click on how to install the library Button given Blow
Code
We load the code and observe how the motor makes a turn in one direction and then another in the opposite direction in a cyclical way.
//For more Projects: www.arduinocircuit.com
#include <Stepper.h>
const int stepsPerRevolution = 48; // Modify this value according to the motor you are using
// initialize the library with the steps to return the motor and the digital pins to which we connect the terminals of our motor
Stepper myStepper(stepsPerRevolution, 12,11,10,9);
void setup() {
// Set the speed to 60 rpm
myStepper.setSpeed(60);
// Initialize the communication series
Serial.begin(9600);
}
void loop() {
// Let's turn around and feel
Serial.println("clockwise");
myStepper.step(stepsPerRevolution);
delay(500);
// Damos una vuelta en el sentido contrario
Serial.println("counterclockwise");
myStepper.step(-stepsPerRevolution);
delay(500);
}
Applications
- Robotics
- CNC machines
- 3D printers
- Camera pan-tilt systems
- Disk drives
Conclusion
Stepper motors are a reliable and accurate method for controlling mechanical motion. By connecting a stepper motor to an Arduino, we can control the movement of a wide range of devices with precision and ease. The 28BYJ-48 stepper motor is an affordable and widely used option for hobbyist projects.