Wiring
straight forward,I just used jumper wires for this.
Stepper Motor wires PairA to L298N Out1 and Out2,
Stepper Motor wires PairB to L298N Out3 and Out4
(how to find pairs at the bottom of this post)
Connect Arduino Pins 8,9,10,11 and GND -to-
L298N In1,In2,In3,In4, and GND
L298N is connected to a 12vdc Power supply
Arduino connected to the PC via USB
Arduino Code (cut and paste)
// Highlight from HERE
///This is a simple sketch to allow the Arduino to control
// a bi-polar stepper motor
// By Andrew Mallinson
// Mallinson-electrical.com
// The Arduino is hooked up to a L798N H bridge
// This allows higher voltage and current to be applied to
// the stepper motor, without damaging the Arduino
//
//
// Define the Arduino pins
int RED = 8; // L298N In1
int YELLOW = 9;//L298N In2
int GREEN = 10;//L298N In3
int BLACK = 11;//L298N In4
// Define some variables
int d = 3; //define delay - adjust this to give smooth running, lower number = higher speed
int s = 200;//steps per rev of stepper
float fwd = 1.5; // number of revs forward required - {Can be any number or increment of 0.02
float rvs = 3.0; // number of revs reverse required - {sequences are 4 steps, 50x 4 steps = 1 rev, so 4 steps=0.02 revs
void setup()
{
pinMode(RED,OUTPUT); // set the pins to be giving signal not receiving
pinMode(YELLOW,OUTPUT);
pinMode(GREEN,OUTPUT);
pinMode(BLACK,OUTPUT);
}
// There are four different steps, because there are 4 permutations of the poles on a bipolar stepper
// Pair Red/Yellow and Pair Green/Black
void Astep() { // This is a subroutine to tell arduino the output which creates the first step
digitalWrite (RED,1); // +ve voltage out of red
digitalWrite (YELLOW,0);// so yellow is -ve
digitalWrite (GREEN,0);// sets green to -ve
digitalWrite (BLACK,1);// so black must have +ve
}
void Bstep() {
digitalWrite (RED,1);
digitalWrite (YELLOW,0);
digitalWrite (GREEN,1);
digitalWrite (BLACK,0);
}void Cstep() {
digitalWrite (RED,0);
digitalWrite (YELLOW,1);
digitalWrite (GREEN,1);
digitalWrite (BLACK,0);
}void Dstep() {
digitalWrite (RED,0);
digitalWrite (YELLOW,1);
digitalWrite (GREEN,0);
digitalWrite (BLACK,1);
}
void forwd()// this is a subroutine to define the sequence of steps to drive the stepper forward
{
Astep(); // Carry out the instruction of a subroutine we created called Astep
delay(d); // wait for a length of time defined in the setup section
Bstep();
delay(d);
Cstep();
delay(d);
Dstep();
delay(d);
}
void rvrs()// define the sequence of steps to drive the stepper in reverse
{
Dstep();
delay(d);
Cstep();
delay(d);
Bstep();
delay(d);
Astep();
delay(d);
}
void loop()
{
int f=(fwd*s/4);// create a new value f based on forward turns required, steps/rev and divide by four (4 seperate steps)
for(int i=0; i<f; i++)// setup a counter called i, if it is less than f(above), we will do this again, so add 1 to i and carry out the instruction below
{
forwd(); // carry out the instructions we defined in subroutine forwd
}
delay(1000); // wait for one second - the number is milliseconds, 1000ms = 1s
int r=(rvs*s/4);
for(int i=0;i<r;i++)
{
rvrs();
}
delay (1000);
}
// Highlight to HERE
Ratings
Stepper motor Voltage = 2.5v supply Voltage = 12v
This is not a problem, when we apply the voltage for a step, there is a rapid increase from 0v towards 12v, but before we get there, we are onto the next step. I have over simplified this, but effectively what we are doing is making the stepper motor more responsive.
Stepper Motor Current = 1.68A, the Arduino is not even close!
No Problem, we will use the Arduino to operate a H Bridge, this device, in simple terms, will act like a big quick switch. When Arduino says go, the L298N will switch a bigger voltage and current to the stepper.
To Find your Stepper Pairs
1st find the two pairs of windings on the stepper motor. Choose any two wires, and see if they are connected to a winding.
You can do this with a multimeter set to Ohms - reading at or around zero, or you can use a battery and an LED. Connect the battery to one stepper wire, the other to one leg of an LED with a resistor.Touch the other LED leg with any of the remaining 3 stepper wires, when it lights you have your pair.
How it works
Bi-Polar stepper motors are not very complicated. The central rotor is magnetic, and by creating a magnetic field in one of the two windings, we make the rotor "step" so that the magnets line up. This effect can be seen simply, by holding two ordinary magnets close to each other, One way they attract, but reverse one and they repel each other.
No comments:
Post a Comment