I will describe the process of stepper motor drive with a 2-phase 4-wire stepper motor as an example. Everyone knows that an energized conductor produces a force in a magnetic field; an energized coil produces a magnetic field. The first one is the principle of DC motor drive, which is not introduced here. The latter principle is the basis of the motion of the stepper motor. Let's take a look at the 2-phase 4-wire stepper motor construction diagram, as follows:
![Driving Stepper Motor Driving Stepper Motor]()
As can be seen from the above diagram, the stepper motor has a rotor and a stator. The so-called rotor, that is, the device is active and can be rotated. The so-called stator is that the device is fixed and does not move. The rotor, the middle magnet, we can see that its N and S poles have been marked. The stator, the outer ring, which has four coils of A (A+), B (B+),A (A-),B (B-), each of which has a lead The externally connected line, where A, A (-) is a phase, is connected, and temporarily calls it A phase, B, B (-) is a phase, is connected, and temporarily calls it phase B. When phase A or phase B is energized, it is turned into a magnet that exerts a strong gravitational force on the magnets on the rotor, thereby pulling the rotor. Of course, the polarity of the magnet must have a certain regularity, and the torque can act in one direction according to its own needs, otherwise the force may be offset, causing the motor to not rotate or tremble after being energized. The energization law of A phase or B phase energization is the timing problem of the familiar stepping motor. Regarding the timing of the motor, we will introduce it with the program below. First explain three important parameters, as follows:
Pitch angle: It means the angle between the two tooth pitches. The 42 stepping motor I used
has 50 teeth, and the pitch angle α=360/50=7.2°.
Number of beats: The number of pulses required to turn a pitch angle, or the number of pulses
required to complete a periodic change in the magnetic field, denoted by
n,The following program is a 4-shot operation mode, that is, AB→BA→AB→AB.
Step angle: indicates the angle θ at which the motor rotates every time the control system sends
a pulse signal. θ = pitch angle / number of beats = 7.2 / 4 = 1.8 °.
The key information we need to use about the stepper motor has been introduced above. The next step is to explain the wiring diagram of the 2-phase 4-wire stepper motor used here, as shown below:
![Driving Stepper Motor Driving Stepper Motor]()
Finally, I used Pieces of codes to illustrate the driving process of the stepper motor. The products have been used: 42 stepper motor; arduino nano development board (HW-284); driver board, L298N driver board (HW-095). The wiring diagram is as follows:
![Driving Stepper Motor Driving Stepper Motor]()
![Driving Stepper Motor Driving Stepper Motor]()
Codes:
#include
#define D2 2 //A+ Black wire----OUT1
#define D3 3 //A- Green wire----OUT2
#define D4 4 //B+ Red wire----OUT3
#define D5 5 //B- Blue wire----OUT4
void setup() {
pinMode(D2,OUTPUT);
pinMode(D3,OUTPUT);
pinMode(D4,OUTPUT);
pinMode(D5,OUTPUT);
}
void loop() {
// The stepping motor used by me is 50 teeth, the pitch angle α=7.2°.if motor is drived in full steps,the step angle β=α/4. the motor turns 1.8° when send a pulse.
/******if the motor Rotated speed is 2rev / s, then you can calculate the width of each pulse , pulse width = (1000 / 2) / (360 ° / 1.8 °) = 2.5ms******/
digitalWrite(D2,HIGH);
digitalWrite(D3,LOW);// A phase forward conduction
digitalWrite(D4,HIGH);
digitalWrite(D5,LOW);// B phase forward conduction
delay(2.5);/*** Set the pulse length to 2.5ms and the motor speed to 2 revolutions per second.***/
digitalWrite(D2,LOW);
digitalWrite(D3,HIGH);// A phase opposite conduction
digitalWrite(D4,HIGH);
digitalWrite(D5,LOW);// B phase forward conduction
delay(2.5);
digitalWrite(D2,LOW);
digitalWrite(D3,HIGH);// A phase opposite conduction
digitalWrite(D4,LOW);
digitalWrite(D5,HIGH);// B phase opposite conduction
delay(2.5);
digitalWrite(D2,HIGH);
digitalWrite(D3,LOW);// A phase forward conduction
digitalWrite(D4,LOW);
digitalWrite(D5,HIGH);// B phase opposite conduction
delay(2.5);
}