How To Control Speed of Stepper Motor by Potentiometer
How To Control Speed of Stepper Motor by Potentiometer
How To Control Speed of Stepper Motor by Potentiometer
sandeep
01/07/2018
zero comment
Hello friends.
In this tutorial we will learn how to run and control speed of Stepper motor using Arduino, A4988 driver IC
and Potentiometer.
You can watch the following video or you can continue to read this post for complete tutorial.
OVERVIEW
A4988 is a Microstepping driver IC to control bipolar stepper motors, A4988 Driver is so easy to use because
it needs only two control pin from microcontoller to control steps and direction of stepper motor. we can
configure A4988 IC for full step, half step, quarter step, eight step & sixteen steps,
1. ENABLE :- Enable pin is used to enable and disable stepper motors, like in some applications if you
don’t need to engage motors while in rest position means you don’t need holding torque, so we just
disable steppers during this rest position and enable them again when it required, in this why motors
will not draw current in holding position and and heating of motor avoids. it is not always compulsory
to used this pin. Enable pin is low motors are enable, Enable pin is high motors are disable.
2. MS1, MS2, MS3 :- This pins are used to configure Microstepping study below table to get idea how
to configure required micostepping.
Following is the arduino code to run stepper motor one step in forward direction and one step in reverse
direction.
1 const int stepPin = 4;
2 const int dirPin = 3;
3 void setup() {
4 // Sets the two pins as Outputs
5 pinMode(stepPin,OUTPUT);
6 pinMode(dirPin,OUTPUT);
7 }
8 void loop() {
9 digitalWrite(dirPin,HIGH); // Enables the motor to move in a particular direction
10 // Makes 200 pulses for making one full cycle rotation
11 for(int x = 0; x < 200; x++) {
12 digitalWrite(stepPin,HIGH);
13 delayMicroseconds(500);
14 digitalWrite(stepPin,LOW);
15 delayMicroseconds(500);
16 }
17 delay(1000); // One second delay
18
19 digitalWrite(dirPin,LOW); //Changes the rotations direction
20 // Makes 400 pulses for making two full cycle rotation
21 for(int x = 0; x < 400; x++) {
22 digitalWrite(stepPin,HIGH);
23 delayMicroseconds(500);
24 digitalWrite(stepPin,LOW);
25 delayMicroseconds(500);
26 }
27 delay(1000);
28 }
1 int steppin = 4;
2 int dirpin = 3;
3 int stepdelay;
4 void setup() {
5 pinMode(steppin, OUTPUT);
6 pinMode(dirpin, OUTPUT);
7 digitalWrite(dirpin, HIGH); // direction pin either LOW or HIGH to move in either direction.
8
9 }
10
11 void loop() {
12 int val = analogRead(A0);
13 stepdelay = map(val,0,1023,1,1000);
14 digitalWrite(steppin, HIGH);
15 delayMicroseconds(stepdelay);
16 digitalWrite(steppin, LOW);
17 delayMicroseconds(stepdelay);
18
19 }