What is a stepper motor & their applications?
Stepper motors are DC motors that move in discrete steps. They have multiple coils that are organised in groups called “phases”. By energising each phase in sequence, the motor will rotate, one step at a time. (source).Where they can be used for many application such as CNC machining, 3D printing, Medical imaging machinery and many more.
There are four different types of stepper motor and they are permanent Magnet, Hybrid, 4 phase unipolar and 2 phase bipolar. for this week we will be using a 4 phase unipolar stepper motor.
Coding a stepper motor
There are 4 different wave types that a Unipolar motor can be driven/ turn and they are:
For this week I will be using full step driver as reference to help me code the stepper motor to turn. If we assume that for every wave that goes up is on and for every wave that goes down is off, we got are self a binary system. By using this idea we can simply use one of Arduno’s example code called blink as a foundation to work from. By changing the LED_ BUILTIN and replace it with the corresponded pins of the stepper motor I will be able to turn the stepper motor by turning each phase on and off according to the full step driver graph above.
Here is the code for it:
void setup() {
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
pinMode(10, OUTPUT);
}
void loop() {
digitalWrite(13, LOW);
digitalWrite(12, LOW);
digitalWrite(11, HIGH);
digitalWrite(10, HIGH);
delay(2);
digitalWrite(13, LOW);
digitalWrite(12, HIGH);
digitalWrite(11, HIGH);
digitalWrite(10, LOW);
delay(2);
digitalWrite(13, HIGH);
digitalWrite(12, HIGH);
digitalWrite(11, LOW);
digitalWrite(10, LOW);
delay(2);
digitalWrite(13, HIGH);
digitalWrite(12, LOW);
digitalWrite(11, LOW);
digitalWrite(10, HIGH);
delay(2);
}
The use of a void loop() function will run the code above over and over again.
Here a circuit diagram on how to set up the stepper motor on to a arduino board:
Here is the actual set up of the circuit:
Another coding for stepper motor:
void setup() {
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
pinMode(10, OUTPUT);
}
void loop() {
unsigned int i = 0;
while ( i < 200){
i=i+1;
//backwards
digitalWrite(13, LOW);
digitalWrite(12, HIGH);
digitalWrite(11, HIGH);
digitalWrite(10, LOW);
delay(2);
digitalWrite(13, LOW);
digitalWrite(12, LOW);
digitalWrite(11, HIGH);
digitalWrite(10, HIGH);
delay(2);
digitalWrite(13, HIGH);
digitalWrite(12, LOW);
digitalWrite(11, LOW);
digitalWrite(10, HIGH);
delay(2);
digitalWrite(13, HIGH);
digitalWrite(12, HIGH);
digitalWrite(11, LOW);
digitalWrite(10, LOW);
delay(2);
}
i = 0;
while ( i < 200){
i=i+1;
//forward
digitalWrite(13, LOW);
digitalWrite(12, LOW);
digitalWrite(11, HIGH);
digitalWrite(10, HIGH);
delay(2);
digitalWrite(13, LOW);
digitalWrite(12, HIGH);
digitalWrite(11, HIGH);
digitalWrite(10, LOW);
delay(2);
digitalWrite(13, HIGH);
digitalWrite(12, HIGH);
digitalWrite(11, LOW);
digitalWrite(10, LOW);
delay(2);
digitalWrite(13, HIGH);
digitalWrite(12, LOW);
digitalWrite(11, LOW);
digitalWrite(10, HIGH);
delay(2);
}
i = 0;
}
This particular code allow the stepper motor to go forwards and backwards. So the concept of this is that i is a unsigned integer where it can be any number so for every loopit will i = i+1 however i has to lower than 200. Meaning i cannot exceed over 200, once it does it will move on to a next loop but resetting i as 0 and this will keep going due the the function of Void loop().
I found this week task to be challenging but very educational at the same time. The reason why found this week task challenging is due to that fact I didn’t know what is a stepper motor was, how they work, and how to code it in order for it to turn, coding in general and setting up the circuit diagram for the stepper motor. However after doing this session I gain more of an understanding of the basic of a stepper motor how they behave as well as coding in arudino which i’m very pleased about.
Leave a Reply