In today’s article, we will be discussing the controlling of a stepper motor with the help of the drv8825 driver and Arduino. Before moving further let us discuss, what actually is a stepper motor.
What IS A Stepper Motor?
A Stepper motor is also known as a Stepping motor or step motor. As its name suggests stepper motor is a direct current(DC) motor which is brushless as well and it divides a full rotation into an equal number of steps or rotations. The internal structure of a Stepper motor is so well-defined that there is no need for any position sensor to get the position of the shaft. It can be calculated using the number of steps that have been performed.
The main function of the Stepper motor is its precise positioning as well as no need for any position sensor for getting the location of the shaft. This motor is widely used in many electronic appliances and products like printers, Security cameras, scanners, ATMs, etc. However, Stepper motors can not run at high speed but they have a high holding torque.
Now let us discuss the requirements of the project.
Materials Required
The materials required for the project are listed below:-
Name | Quantity |
drv8825 driver | 1 |
NEMA 17 Stepper Motor | 1 |
Arduino UNO Rev 3 | 1 |
Capacitor 100uF | 1 |
Power Supply | 8 – 45v |
Breadboard | 1 |
Jumper Wires | 10 |
5v DC Adapter | 1 |
DRV8825 Stepper Motor Driver
At the center of the driver, there is a chip available which is also known as the “Heart OF The Module.” The drv8825 driver module is developed by Texas Instruments and has features like adjustable current limiting capability, over-current and over-temperature protection capability, and six different microstep resolutions which we will discuss later.
The DRV 8825 module is used for interfacing with the microcontroller. It has an in-built translator which makes it more easy to interface. There are only two input pins available on the module which are needed to control the Bipolar stepper motor. These input pins take commands in the form of High(1) and Low(0). After each High signal, a Low signal is there which makes it easier for the motor to understand when a new step command is given.
The first pin which is the DIR pin is used to control the direction of the rotation and the other pin which is the STEP pin is used to control the step of the motor.
The drv8825 driver operates in 6 steps which are full-step, half-step, quarter-step, eighth-step, sixteenth-step, and thirty-second-step.
The drv8825 driver has an output capacity of 45v as well as the output current is regulated which helps in noiseless operation.
Technical Specifications OF The DRV8825 Stepper Motor Controller
Motor output voltage | 8.2V – 45V |
Continuous current per phase | 1A |
Microstep resolution | full, 1/2, 1/4, 1/8, 1/16, and 1/32 |
Maximum current per phase | 2.5A |
Logic voltage | Built-In 3.3V output |
Reverse voltage protection | No |
Dimensions | 15.5 × 20.5 mm (0.6″ × 0.8″) |
Pinout OF The DRV 8825 Stepper Motor Controller
Pin Number | Pin Name |
1 | EN(Active low input pin) |
2 | M0 |
3 | M1 |
4 | M2 |
5 | SLP(Active low input pin) |
6 | RST(Active low input pin) |
7 | STEP |
8 | DIR |
9 | GND Logic |
10 | Fault |
11 | A2 |
12 | A1 |
13 | B1 |
14 | B2 |
15 | GND MOT |
16 | VMOT |
Power Pins
The drv8825 driver has VMOT(pin 16) and GND MOT(Pin 15) as its power pins. Any voltage supply between 8.5v to 45v can be connected to these pins.
Pin Number | Pin Name |
15 | GND MOT |
16 | VMOT |
The module does not have any logic pin because it has a 3v3 regulator with the help of which it draws power from the motor power supply.
Microstep Selection Pin
As stated earlier there are a total of 6 different types of microsteps resolutions possible. These resolutions are selected using these Microstep Selection pins which are M0, M1 and M2.
Pin Number | Pin Name |
2 | M0 |
3 | M1 |
4 | M2 |
For selecting any particular step resolution proper logic levels are needed to be maintained on the above-mentioned micro step selection pins.
M0 | M1 | M2 | Microstep Resolution |
Low | Low | Low | Full step |
High | Low | Low | Half step |
Low | High | Low | 1/4 step |
High | High | Low | 1/8 step |
Low | Low | High | 1/16 step |
High | Low | High | 1/32 step |
Low | High | High | 1/32 step |
High | High | High | 1/32 step |
Control Input Pins
As mentioned above the control input pins are the pins that decide the direction of the rotation of the shaft and the step size. There are 2 control pins available which are DIR and STEP.
Pin Number | Pin Name |
7 | STEP |
8 | DIR |
DIR is responsible for the direction of the rotation, when this pin sets at High the motor rotates clockwise and when it sets at Low the motor rotates anti-clockwise.
Note:- If you want to rotate the motor only in one direction then you can connect DIR directly to Vcc or GND.
STEP is responsible for the micro-steps of the motor. At every HIGH pulse, this pin drives the motor according to the number of micro steps determined by the microstrip selection pins. The higher the pulse frequency, the faster the motor will spin.
Power State Control Pins
There are 3 pins available that work as Power state control pins. These pins are needed to control the power states. The pins are EN, RST, and SLP.
EN – This pin is an active low-input pin. Whenever this pin is pulled at Low the DRV 8825 module enables. By default, this pin is at Low. This pin is generally used to emergency stop or shut down the system.
Pin Number | Pin Name |
1 | EN(Active low input pin) |
SLP – This pin is also an active low-input pin. Whenever this pin is at Low the driver gets into sleep mode. This pin is mainly used to save power when the motor is not in use.
Pin Number | Pin Name |
5 | SLP(Active low input pin) |
RST – This is also an active low-input pin. When this pin is pulled at Low all the STEP inputs get ignored. It also resets the driver module.
Pin Number | Pin Name |
6 | RST(Active low input pin) |
Fault Detection Pin
This pin is used to detect any fault in the circuit. The module has a Fault output that gets low whenever there is any fault due to over-current protection or thermal shutdown. Whenever this pin is pulled to Low, the entire chip is disabled and it will remain disabled until it is either RESET or Motor Voltage VMOT is removed and reapplied.
Pin Number | Pin Name |
10 | Fault |
Output Pins
There are a total of 4 output pins available which are A1(12), A2(11), B1(13), and B2(14). Any small to medium-sized bipolar stepper motor can be connected to these pins. Each pin can supply up to 2.5a of current to the motor.
Pin Number | Pin Name |
12 | A1 |
11 | A2 |
13 | B1 |
14 | B2 |
Cooling System or Heat Sink
As excessive power dissipation takes place in the proper functioning of the module the temperature rises which can cause the burning of the IC when the temperature rises above the bearable capacity of the chip. To overcome this issue a cooling system is required. The heat sink is already available on the chip so this issue won’t arise.
Setting Up The Current Limit
Setting up the current limit is as important as the proper functioning of the stepper motor. If we do not set the limit of the current before connecting to the motor it may cause damage to the motor. For this purpose we use the following equation:-
Current Limit = VRef x 2
Interfacing The DRV8825 and Stepper Motor With The Arduino UNO Rev 3
Now that we know everything about the DRV 8825 Stepper motor driver, we are going to connect the motor to the Arduino Uno.
The connections are not difficult as it seems to be. The steps are listed below:-
Step 1:- Connect the RESET pin to the adjacent SLEEP pin and 5V pin on the Arduino.
Step 2:- Now connect the GND Logic pin to the Arduino’s ground pin.
Step 3:- Connect the DIR pin and STEP pin to the Arduino’s digital output pins(i,e. Pin 2 and Pin 3).
Step 4:- Connect the stepper motor to the A1, A2, B1, and B2 pins.
Step 5:- For using the stepper motor in full step mode keep the micro-step selection pin disconnected.
Step 6:- At last connect the VMOT and GND MOT pins to the power supply. Also, add a 100 microfarad capacitor in between the motor power supply pins to avoid any type of voltage sparks that can damage the circuit.
AccelStepper Library
Now we have completed the connection of Arduino with the motor, now we will start coding the Arduino but before moving further let us understand what is Accelstepper library and how it is used.
The AccelStepper library is used whenever we want to connect multiple stepper motors with acceleration and deceleration. Some of the features of the Accelstepper library are –
- It supports Acceleration and Deceleration.
- Supports Stepper drivers.
- Very slow speeds are also supported.
- Extensive Application Protocol Interface(API).
- Supports Subclass.
- Supports 2, 3, and 4 wire steppers and 3 and 4 wire half steppers.
- Provides an Object Oriented interface for 2,3 or 4-pin stepper motors.
That is all in the features of the Accelstepper Library features.
How to install the AccelStepper library?
- Open your Arduino IDE.
- Head to the sketch menu.
- Click on include library.
- Then click on manage libraries.
- Search AccelStepper in the search bar.
- Select the version and install the library.
Coding Using AccelStepper Library
Below is the code which is required for the project.
#include <AccelStepper.h>
#define dirPin 2
#define stepPin 3
#define motorInterfaceType 1
AccelStepper stepper = AccelStepper(motorInterfaceType, stepPin, dirPin);
void setup() {
stepper.setMaxSpeed(1000);
}
void loop()
{
stepper.setCurrentPosition(0);
while(stepper.currentPosition() != 400)
{
stepper.setSpeed(200);
stepper.runSpeed();
}
delay(1000);
stepper.setCurrentPosition(0);
while(stepper.currentPosition() != -200)
{
stepper.setSpeed(-600);
stepper.runSpeed();
}
delay(1000);
stepper.setCurrentPosition(0);
while(stepper.currentPosition() != 600)
{
stepper.setSpeed(400);
stepper.runSpeed();
}
delay(3000);
}
Frequently Asked Questions
Q1 – Are stepper motors ac or dc?
Ans – A Stepper motor is a brushless DC motor.
Q2 – Are stepper motors waterproof?
Ans – Yes, Stepper motors are waterproof as well as dustproof.
Q3 – How long do stepper motors last?
Ans – A Stepper motor can work for 10,000 operational hours which is equivalent to 4.8 years.
Q4 – Why are stepper motors used?
Ans – A Stepper motor is used to divide a single full rotation into a number of much smaller and equal portions of rotations.