How To Control Speed of Stepper Motor by Potentiometer

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

How to control speed of Stepper motor

by potentiometer + arduino + A4988


Tutorial

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,

PIN DETAILS OF A4988 DRIVER IC

A4988 DRIVER IC PIN DETAIL

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.

A4988 Microstepping table


3. RESET :- Turn off all the FET outputs till when reset pin is high all steps are ignored.
4. SLEEP :- When set low minimize the power consumption and and A4988 went in sleep mode.
5. STEP :- Step pin connected with digital pin of microcontroller to run stepper motor as per the
numbers of step signals from microcontroller, speed of stepper motor depends upon the the frequency
of step signal more the delay in step signal lower the RPM & vice versa. step signal delay is
universally prepositional to the speed of stepper motor.
6. DIR :- Direction pin set high or low to run stepper motor in either direction.
7. V MOT :- Power supply for Motors (8-35V DC).
8. GND :- System ground.
9. 1A,1B,2A,2B :- Connection pin for motor connection.
10. VDD :- Logic power supply (3V – 5.5V).
11. GND :- System ground.

Basic wiring drawing to run Stepper


motor

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 }

Wiring drawing to control speed of


Stepper motor with potentiometer
Following is the code to control speed of stepper motor by using 10k ohm potentiometer

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 }

You might also like