How to Connect Stepper Motor with Arduino Tutorial

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 UNO1Buy Now
Stepper Motor (28BYJ-48) 5v1Buy Now
H bridge L293D1Buy Now
2.1mm Jack Screw Terminal1Buy Now
9v DC Adapter (Optional)1Buy Now
Jumper WiresFewBuy Now
Breadboard1Buy 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

  1. Precise control and positioning
  2. Low power consumption
  3. High torque at low speeds
  4. The reversible direction of rotation

Pinout of Stepper Motor

Stepper-Motor-Pinout-wiring

Pin Configuration of Motor

Pin NameWire ColorDescription
Coil 1OrangeThis 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 2Pink
Coil 3Yellow
Coil 4Blue
+5VRedThis 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

L293D-h-bridge-motor-Pinout

Pin Configuration of H-bridge

Pin NameDescription
Enable 1,2This pin enables the input pin Input 1(2) and Input 2(7)
Input 1Directly controls the Output 1 pin. Controlled by digital circuits
Output 1Connected to one end of  Motor 1
GroundGround pins are connected to ground of circuit (0V)
GroundGround pins are connected to ground of circuit (0V)
Output 2Connected to another end of  Motor 1
Input 2Directly controls the Output 2 pin. Controlled by digital circuits
Vcc2 (Vs)Connected to Voltage pin for running motors (4.5V to 36V)
Enable 3,4This pin enables the input pin Input 3(10) and Input 4(15)
Input 3Directly controls the Output 3 pin. Controlled by digital circuits
Output 3Connected to one end of Motor 2
GroundGround pins are connected to ground of circuit (0V)
GroundGround pins are connected to ground of circuit (0V)
Output 4Connected to another end of Motor 2
Input 4Directly 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

How-to-Connect-a-Stepper-Motor-to-Arduino-circuit

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

  1. Robotics
  2. CNC machines
  3. 3D printers
  4. Camera pan-tilt systems
  5. 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.

See Also Stepper Motor Control with Joystick and Arduino

Leave a Comment


error: