Stepper Motor Interfacing with Arduino

3,690 views

There are multiple kinds of motion we face in our daily life some are linear some are rotatory motions. Both motions have their importance in machines and our lives. And by controlling these motions we can accomplish many tasks. Here we are going to control the stepper motor by using an Arduino board and IC L293D (H bridge motor controller). The L293D is designed to provide bidirectional drive currents of up to 600 mA at voltages from 4.5 V to 36 V. This is designed to drive inductive loads such as relays, solenoids, DC, and bipolar stepping motors. The Stepper motor has an additional DC power source depending on the voltage rating of the stepper motor.

Stepper Motor

A stepper motor is an electromechanical device that converts electrical energy into mechanical power. At the same time, a stepper motor is a brushless, synchronous motor that can divide a full rotation into a huge number of steps. When a stepper motor is applied with electrical command pulses in the proper sequence, the shaft or spindle of the stepper motor rotates in discrete steps, allowing precise control of the motor’s position without any feedback mechanism, as long as the motor is sized for the application. It can hold the current position if the supply is not given, the stepper motors have been classified as Unipolar and Bipolar.

Unipolar Stepper Motor

A unipolar stepper motor has one winding with a center tap per phase. Each section of windings is switched on for each direction of the magnetic field. Typically, given a phase, the center tap of each winding is made common: three leads per phase and six leads for a typical two-phase motor. Often, these two-phase commons are internally joined, so the motor has only five leads. Hence it comes with 5, 6, and 8 leads and operates one winding with the center tap per phase of input. This image shows different types of unipolar stepper motors and their lead configuration, refer datasheet of your stepper motor to know more.

Bipolar Stepper Motor

Bipolar motors have a pair of single winding connections per phase. The current in a winding needs to be reversed in order to reverse a magnetic pole, so the driving circuit must be more complicated, typically with an H-bridge arrangement (however there are several off-the-shelf driver chips available to make this a simple affair). There are two leads per phase, none is common. It has a single winding per phase and only 4 leads to connect two sets of internal electromagnet coils, forward and reverse steps can be achieved by changing the direction of current through the motor coils. This may be more complicated than unipolar, but the H-bridge and stepper motor driver circuits make it very simple.

Hardware Required

S.noComponentValueQty
1.Motor Driver ICL2913D1
2.Stepper Motor1
3.ArduinoUno1
4.Connecting Wires
5.Battery9V1

Stepper Motor Controller Shield

We need a separate motor diver module to operate the stepper motor speed and direction control, as it cannot run by using the microcontroller’s DC bias. This module contains H bridge L2913D motor driver IC and provides connectors to motor bias Vin, GND, and A-, A+ & B-, B+ connectors for the bipolar stepper motor. First, we need to identify the stepper motor terminals and then connect them with this module without tension. It has a board regulator and voltage limiter components. Also, we can use separate IC L293D without a shield.

Arduino Stepper Motor Hookup

arduino-stepper-motor-controller-Diagram

For hookup, connect the stepper motor’s first phase leads A+, A- to the motor driver module that is connected to the first phase of the stepper motor to Pin3, 6 of IC L293D. Then this will give the output 1 and 2 for the first phase winding, connecting phase two leads B+, B- to the module (second phase of stepper motor to pin 11, 14 of IC L293D). Now to power, the circuit connects separate DC voltage in Vin, GND pin of the motor driver. Further, refer datasheet of IC L293D and the stepper motor to identify the correct phase leads. If the stepper motor does not run properly then check the motor leads it may interchange within polarity and make connections after referring datasheet.

Arduino Code:

As Present in the Example (Use this code when you use a Bipolar stepper and L298N dual H bridge)

#include <Stepper.h>

const int stepsPerRevolution = 200;  // change this to fit the number of steps per revolution
// for your motor

// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);

void setup() {
  // set the speed at 60 rpm:
  myStepper.setSpeed(60);
  // initialize the serial port:
  Serial.begin(9600);
}

void loop() {
  // step one revolution  in one direction:
  Serial.println("clockwise");
  myStepper.step(stepsPerRevolution);
  delay(500);

  // step one revolution in the other direction:
  Serial.println("counterclockwise");
  myStepper.step(-stepsPerRevolution);
  delay(500);
}

Arduino Code As per the Hookup Made

(Use this code when you use a Bipolar stepper motor and L293D IC)

#include <Stepper.h>
 
int in1Pin = 12;
int in2Pin = 11;
int in3Pin = 10;
int in4Pin = 9;
 
// change this to the number of steps on your motor
#define STEPS 512
 
Stepper motor(STEPS, in1Pin, in2Pin, in3Pin, in4Pin); 
 
void setup()
{
  pinMode(in1Pin, OUTPUT);
  pinMode(in2Pin, OUTPUT);
  pinMode(in3Pin, OUTPUT);
  pinMode(in4Pin, OUTPUT);
 
  // this line is for Leonardo's, it delays the serial interface
  // until the terminal window is opened
  while (!Serial);
   
  Serial.begin(9600);
  motor.setSpeed(20);
}
 
void loop()
{
  if (Serial.available())
  {
    int steps = Serial.parseInt();
    motor.step(steps);
  }
}

Finally upload the Arduino sketch to control the stepper motor, here as the new Arduino IDE 1.6.9 has an inbuilt library for the stepper motor. So you can use those example programs to run the stepper motor, if you don’t have then google it to download the library and examples. If the stepper motor does not run properly then check the motor leads it may interchange within polarity and make connections after referring datasheet.

Applications

  • Industrial Machines – Stepper motors are used in automotive gauges and machine tooling automated production equipment.
  • Security – new surveillance products for the security industry.
  • Medical – Stepper motors are used inside medical scanners, and samplers, and are also found inside digital dental photography, fluid pumps, respirators, and blood analysis machinery.