Bipolar Stepper Motor Control By Arduino

 Bipolar Stepper Motor Control By Arduino

About This Project:-


By this post you will learn how to drive a bipolar stepper motor by using arduino and motor driver IC (L293D).Stepper motor are useful when you are looking for a motor having repeatability(Repeatability is a drive mechanism’s ability to return to the same position multiple times under identical conditions.) and accuracy(Accuracy is the degree in measurement for motion can be determined to which the final position matches the commanded position.).
 

Used In This Project :-

1)  Arduino UNO

2) L293D motor driver

3) Breadboard

4) Jumper wires

5) Arduino IDE

6) Bipolar stepper motor

7)  And ofcourse My Brain


Basics About Hardware:-


* L293D Motor Driver

L293D is a basic motor driver IC that enable us to drive a  DC motor at a time in either direction and also control the speed if the motor. It has totally 16 pin.  A single L293D IC is capable of running two dc motors at the same time; also the direction and speed of these two motors can be controlled independently, or can drive a single bipolar or unipolar stepper motor at a time.






  L293D Pin Configuration



                                 
# Enable 1,2 -   By applying voltage on this pin we can enable output pin 1&2, we can also apply                                    PMW signal to this pin in order to regulate the voltage of output3 & output 4 .

 # Input 1 -       It is basically an input pin, it has two state HIGH (Logic 1) or LOW (Logic 0). When                              this pin is given HIGH or Logic 1, the output 1 become HIGH And when this pin is                                given LOW or Logic 0, the output 1 become LOW.

# Output 1 -     It is basically an output pin, it also has two state  HIGH (Logic 1) or LOW (Logic 0).                               This pin is connected to one of the terminals of the motor .

# Ground -       L293D IC has totally 4 Ground pin, all are internally connected and it Should be                                      connected to the circuit's ground (0V).

# Output 2 -      It is basically an output pin, it also has two state  HIGH (Logic 1) or LOW (Logic 0).                               This pin is connected one of the terminals of the motor .


 # Input 2 -       It is basically an input pin, it has two state HIGH (Logic 1) or LOW (Logic 0). When                              this pin is given HIGH or Logic 1, the output 2 become HIGH And when this pin is                                  given LOW or Logic 0, the output 2 become LOW.


# Vcc 2 (Vs) -   Vcc 2 is an input pin , it is the voltage required to run the motor. We can connect this                                pin to the power supply between 4.5V to 36V.



# Enable 3,4 -   By applying voltage on this pin we can enable output pin 3&4, we can also apply                                    PMW signal to this pin in order to regulate the voltage of output3 & output 4 .



 # Input 3 -       It is basically an input pin, it has two state HIGH (Logic 1) or LOW (Logic 0). When                              this pin is given HIGH or Logic 1, the output 3 become HIGH And when this pin is                                 given LOW or Logic 0, the output 3 become LOW.



# Output 3 -     It is basically an output pin, it also has two state  HIGH (Logic 1) or LOW (Logic 0).                               This pin is connected to one of the terminals of the motor .



# Ground -       L293D IC has totally 4 Ground pin, all are internally connected and it Should be                                      connected to the circuit's ground (0V).



# Output 4 -      It is basically an output pin, it also has two state  HIGH (Logic 1) or LOW (Logic 0).                               This pin is connected one of the terminals of the motor .


 # Input 4 -       It is basically an input pin, it has two state HIGH (Logic 1) or LOW (Logic 0). When                              this pin is given HIGH or Logic 1, the output 4 become HIGH And when this pin is                                  given LOW or Logic 0, the output 4 become LOW.


# Vcc 1 (Vss) -  Vcc 1 is an input pin , it is the voltage required to enable IC function, It is connected to                            5V.



* Bipolar stepper motor



A stepper motor is a brushless DC motor that divides a full rotation into several equal steps. The motor's position can then be directed to move and hold at one of these steps. A bipolar stepper motor has one winding per stator phase. A two phase bipolar stepper motor will have 4 leads. In a bipolar stepper, we don’t have a common lead like in a unipolar stepper motor .











The basic working principle of the stepper motor is the following: By energizing one or more of the stator phases, a magnetic field is generated by the current flowing in the coil and the rotor aligns with this field. By supplying different phases in sequence, the rotor can be rotated by a specific amount to reach the desired final position. Figure 2 shows a representation of the working principle. At the beginning, coil A is energized and the rotor is aligned with the magnetic field it produces. When coil B is energized at same time  the rotor rotates clockwise by 45° to align with both magnetic field, After that when coil A  de-energized the rotor rotates clockwise by 45° to align with  magnetic field produced by coil B, In next step when again coil A  energized but in opposite polarity again the rotor rotates clockwise by 45° to align with both magnetic field, In this way rotor rotate in bipolar stepper motor.



Circuit Diagram :-








Step 1
             The connection are quite simple. Start by connecting Arduino's 5V and GND pin to the                            breadboard.

Step 2
             Now connect the Vcc1 (Vss) , Enable 1,2  and Enable 3,4 to 5V.

Step 3  
              Now connect the Vcc2 (Vs) of IC to external voltage source, that you are using for driving the               motor .

Step 4
              Now connect all the ground of the circuit to each other.

Step 5 
               Now connect input1, input2, input3 & input4 to the Arduino pin 9, 10, 11 & 12 respectively.


Step 6
              Now connect the output1, output2, output3 and output4 to coil A+,  coil A-,  coil B-                                 and  coil B+  respectively.


Coding :-

// Number of steps per output rotation

const int stepsPerRevolution = 200;

// Create Instance of Stepper library

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


void setup()
{
	// set the speed at 60 rpm:

	myStepper.setSpeed(60);
	
}

void loop() 
{
	// step one revolution in one direction:
	
	myStepper.step(stepsPerRevolution);

	delay(500);

	// step one revolution in the other direction:
	
	myStepper.step(-stepsPerRevolution);

	delay(500);
}

Code Explanation:

The sketch starts with including Arduino stepper library. The stepper library comes packaged with the Arduino IDE and takes care of sequencing the pulses we will be sending to our stepper motor.

// Include the Arduino Stepper Library
#include <Stepper.h>

After including the library we define a variable named stepsPerRevolution. As the name suggests it's is the number of step take in one revolution . it means if you give a signal to motor to start rotating in either clockwise or counterclockwise direction then motor rotate that amount of steps in one signal.

In my case in one signal motor rotate 200 steps in one direction. you also can change your stepsPerRevolution. according to your requirement.

// Number of steps per output rotation
const int stepsPerRevolution = 200;

Next, we create an instance of the stepper library. It takes the steps per revolution of motor & Arduino pin connections as parameter.

// Create Instance of Stepper library
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);



In setup section of code, we set the speed of stepper motor by calling setSpeed() function .

void setup()
{
	// set the speed at 60 rpm:
	myStepper.setSpeed(60);
	
}


In loop section of code, we simply call step() function which turns the motor a specific number of steps at a speed determined by setSpeed() function.  By placing negative sign number to this function reverses the spinning direction of motor.

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

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


                       ##################  I Hope You Got It ###################