• Pooja Velavan

Interfacing Stepper Motor with Arduino

The Stepper Motor is an electromechanically controlled device that converts electrical power into mechanical power, mostly stepper motor is used for controlled stepping with accurate speed control and also with a change in the direction.


In this article, let us learn about how to #interface a stepper motor with Arduino along with its circuit diagram and coding part.


Hardware Requirements:


1. Breadboard


Breadboard

A breadboard is a rectangular board with small holes in it that are used for connecting elements. The connections are not fixed and can be varied. In a breadboard, the holes in one horizontal line are in series connection with each other. Breadboards are made from plastic and come in all shapes, sizes, and even different colors, the most commonly used sizes for circuit connections are "full-size," "half-size," and "mini" breadboards.


Buy Breadboard from here.


2. Arduino UNO R3


Arduino UNO_R3

Arduino #UNO R3 is the most commonly used and latest version among the Arduino board. Arduino Board can address inputs such as light on a sensor, Twitter information, a finger on a button, and turn it to an output such as initiating a motor, turning on an LED, advertising something online. All of this can be done by transferring a set of instructions to the microcontroller on the board by the use of the Arduino programming language.


Buy Arduino UNO R3 from here.


3. 28BYJ48 - Stepper Motor

28BYJ48 Stepper Motor

28-BYJ48 type is the most frequently used stepper #motor. The application of this stepper motor includes a 3D printer, Surveillance camera, DVD drivers, etc. The stepper motor consists of 5-leads in which 4-unipolar coil leads and one supply lead (5V). On working stepper motor consumes higher current and hence it is mandatory to connect a driver IC like #ULN2003 to it.


Buy 28BYJ48 Stepper Motor from here.


4. ULN2003A - Driver Board

ULN2003A - Driver Circuit

ULN2003A Driver has a 16 pin Integrated Circuit. It has seven Darlington pairs in which each pair is capable of driving the output load up to 500mA, 50V. The Driver Circuit consists of 7-input and 7-output pins and 1-common and 1-ground pin.


Buy ULN2003A - Driver Circuit from here.


5. MB102 Power Supply Module

MB102 Power Supply Module

MB102 #Power Supply Module is the most useful breadboard component to supply the operating voltage of 3.3V / 5V. It accepts 6.5-12V as an input voltage and produces an independent channel of output voltage that has 3.3V or 5V with a maximum output current of 700mA. It has 5-pins, those are left jumper, right jumper, 4-Berg header for Ground, and 2-Berg Header for 3.3/5V.


Buy MB102 Power supply module from here.


6. 9V Battery

9V Battery

This is the main component to provide power to the #stepper motor.


Buy 9V Battery from here.


7. Connecting Wires

These are the main components that are used to establish the connections between different devices of the circuit.



Connecting Wires

Buy Connecting Wires from here.


8. USB Cable

This cable is used to connect the Arduino to the computer/ laptop to upload the program. It also helps in the transmission of data.



USB Cable

Buy USB Cable from here.


Software Requirements:


1. Arduino IDE

Arduino IDE (Integrated Development Platform) which is used to interface the boards like #NodeMCU to run the desired code designed to interface hardware devices.



Arduino IDE LOGO

Circuit Connection:

Let us see how to interface #Arduino UNO- R3 with a 28-BYJ48 type stepper motor.


Circuit Connections

The 5-pins connector of the 28-BYJ48 type stepper motor is connected to the ULN2003A Driver board connector. The IN1, IN2, IN3, IN4 pins of the #ULN2003A Driver board are connected to the Arduino digital pins 8,9,10, and 11 respectively. There is an external power supply used because Arduino alone cannot handle the stepper motor. Then the power terminal (Vcc) of the Driver board is connected to the positive terminal of the breadboard which is further connected to the positive pin of the power supply module.


Similarly, connect the ground pin of the driver board to the negative terminal of the breadboard in which the negative pin of the power supply module is connected. Next, connect the Ground pin of the Arduino to the negative terminal of the breadboard to establish a common ground connection.


Coding Explanation:

The following code needs to be entered into the Arduino IDE and uploaded to the Arduino board.

#include <Stepper.h> // stepper motor header file
const int stepsPerRevolution = 2048;  // steps per revolution (32 * 64)

Include the above-given Header file from the Arduino built-in stepper library. Initialize the number of steps that the motor need for one revolution.

Stepper stepper(stepsPerRevolution, 8, 10, 9, 11);

The motor terminals that are connected to the Arduino pins 8, 9, 10, and 11 are assigned.

const int revPerMinute = 15;   // rpm of stepper motor is set to 15 rpm
int inputSteps = 0;

Initialize the revolution per minute (rpm) to 15 rpm and declare the initial steps to 0.

void setup() {
  Serial.begin(9600);     // buad rate = 9600
  stepper.setSpeed(revPerMinute);     // speed of motor is set to 15rpm
}

In the Void setup, the baud rate is set to 9600, and the speed of the stepper motor is set to 15 rpm.

void loop() {
  if(Serial.available())
  
  {
    inputSteps= Serial.parseInt();
    Serial.print("Number of steps : ");
    Serial.println(inputSteps);       // no. of steps entered by user 
    stepper.step(inputSteps);
  }
}

In the Void loop function, the number of steps can be entered and printed in the Serial #Monitor and this makes the motor rotate. This looping function can be repeated by entering the number of steps to rotate the motor in any direction.


Complete Code

#include <Stepper.h> // stepper motor header file
const int stepsPerRevolution = 2048;  // steps per revolution (32 * 64)

Stepper stepper(stepsPerRevolution, 8, 10, 9, 11);

const int revPerMinute = 15;        // rpm of stepper motor is set to 15 rpm
int inputSteps = 0;

void setup() {
  Serial.begin(9600);     // buad rate = 9600
  stepper.setSpeed(revPerMinute);     // speed of motor is set to 15rpm
}

void loop() {
  if(Serial.available())
  
  {
    inputSteps= Serial.parseInt();
    Serial.print("Number of steps : ");
    Serial.println(inputSteps);       // no. of steps entered by user 
    stepper.step(inputSteps);
  }
}

For the complete code for this program, download the following document.

Stepper_Motor_Interfacing_Code
.txt
Download TXT • 660B

Note: Please change the file extension to .ino(Arduino IDE) file format before you upload the code to the Arduino board.


Working:

The Working of the Stepper Motor involves simple steps. The below image shows the picture of the circuit when the code is not applied.


Image Before insertion of Value

On uploading the program to the Arduino board by using a #USB cable. Open the Serial Monitor, and enter the number of steps the stepper motor is to be rotated. To make a half revolution enter 1024 for the clockwise direction and -1024 for the anticlockwise direction.


The below image shows the stepper motor rotation in an anticlockwise direction when the number of steps is entered has -512.

Image After Insertion of Value

Video explanation with the practical implementation, for a more beneficial perception.


Video By - Anupama Koley

This article covers the basic interfacing of stepper motor with Arduino. With this essential concept, one can build many other projects as stepper motor finds numerous applications 3D printing, tape drives, floppy disc drives, printers, and electric watches, etc.


See Also:

1. Interfacing DC Motor with Arduino

2. Interfacing Servo Motor with Arduino

3. Interfacing Temperature Sensor with Arduino

  • Facebook
  • YouTube
  • Instagram
  • LinkedIn
LearnElectronics
Contact Us
© Copyright - LearnElectronics 2020.