Pages

Monday, July 8, 2013

DRIVING BIPOLAR STEPPER MOTOR WITH ARDUINO + L298N


Ever removed removing stepper motors from old printers. Well, most of the stepper tors you find in the old printers are bipolar stepper motors. Bipolar stepper motors have a permanent magnet rotor and two coils in a stator at 90 degrees to each other. 


Simple bipolar stepper


Above is a simple diagram of one. In driving bipolar stepper motors equal currents are applied to both the coils. The motor is stepped by varying the direction of current in each coil. The below diagram shows the full stepping sequence of the above stepper motor by doing so

Full step sequence of a bipolar stepper motor



The above motor has a full step angle of 45 degrees. This step angle or resolution can be improve by increasing the poles on the motor. Typical step value of a bipolar motor may either be 1.8 degrees(200 steps per revolution) or 7.5 degree steps(48 steps per revolution). These could be halved by using a half- step sequence where between each step indicated above current in the coil whose current is reversed, is switched off before reversing. Hence steps can be reduced to 0.9 degree steps or 3.75.

Enough on the details, let's get onto the driving one. The motor I used was one with full step of 7.5 degree step angle. A voltage of 9v were applied to the motor while it drew a current of about 100mA during operation. I used Arduino mega 2560 which was interfaced with L298N motor controller circuit for the purpose

L298N motor driver ciruit

Diodes were used for protection from inductive load of the motor. Datasheet of L298N recommends fast diodes, so 1N4148 were used. Input pins of the L298N were connected to Digital pins of the Arduino which I have mentioned in my code below. Logic supply voltage of L298N (pin4 - Vs) was connected to +5v pin of Arduino while the ground of the circuit was connected to ground pin of Arduino in order to supply common ground for logic operations.

The next step was to program the arduino. The following code was written to drive the motor continuously in one direction

//defining connections to L298N
int input1 = 22;
int input2 = 23;
int input3 = 28;
int input4 = 29;

void setup()
{
  pinMode(input1,OUTPUT);
  pinMode(input2,OUTPUT);
  pinMode(input3,OUTPUT);
  pinMode(input4,OUTPUT);
}

void loop()
{
//1st step
digitalWrite(input1,HIGH);
digitalWrite(input2,LOW);
digitalWrite(input3,LOW);
digitalWrite(input4,HIGH);
delay(10);  //small delay between each step of 10ms

//2nd step
digitalWrite(input1,LOW);
digitalWrite(input2,HIGH);
digitalWrite(input3,LOW);
digitalWrite(input4,HIGH);
delay(10);

//3rd step
digitalWrite(input1,LOW);
digitalWrite(input2,HIGH);
digitalWrite(input3,HIGH);
digitalWrite(input4,LOW);
delay(10);

//4th step

digitalWrite(input1,HIGH);
digitalWrite(input2,LOW);
digitalWrite(input3,HIGH);
digitalWrite(input4,LOW);
delay(10);
}

Arduino was given 9v and the circuit was powered up. Ta - Dah. Here you go. Your application may vary from driving the motor continuously in one direction. Now, its all up to you to make-break this code to tune into your application. Cheers :)

7 comments:

  1. Can this board be used to drive a 6V 0.6-1A/phase, or would it be better to get the Big Easy?

    ReplyDelete
    Replies
    1. Sorry for the delay
      Answer is yes. L298 is capable

      Delete
  2. hi need help with this driver www.escapmotor.com/MYCOM/pdf/2_phase_stepper/ims200.pdf‎

    ReplyDelete
  3. hi..thx a lot
    but i have a request ..if you can paste the code of double direction plz i need it urgent

    ReplyDelete
  4. The schematic, pin 9 and pin 4 should be swapped.. logic voltage is pin 9 (Vss) which is 5 Volts and the Supply voltage which supply the internal of IC and supply the motor is pin 4 (Vs). Based from datasheet Vs can handle up to 46 volts.

    ReplyDelete