How To Control a Stepper Motor With DRV8825 Driver And Arduino

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:-

NameQuantity
drv8825 driver1
NEMA 17 Stepper Motor1
Arduino UNO Rev 31
Capacitor 100uF1
Power Supply8 – 45v
Breadboard1
Jumper Wires10
5v DC Adapter1

DRV8825 Stepper Motor Driver

DRV8825 Driver onboard component

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 voltage8.2V – 45V
Continuous current per phase1A
Microstep resolutionfull, 1/2, 1/4, 1/8, 1/16, and 1/32
Maximum current per phase2.5A
Logic voltageBuilt-In 3.3V output
Reverse voltage protectionNo
Dimensions15.5 × 20.5 mm (0.6″ × 0.8″)

Pinout OF The DRV 8825 Stepper Motor Controller

Control a Stepper Motor With DRV8825 Driver  and pinout
Pin NumberPin Name
1EN(Active low input pin)
2M0
3M1
4M2
5SLP(Active low input pin)
6RST(Active low input pin)
7STEP
8DIR
9GND Logic
10Fault
11A2
12A1
13B1
14B2
15GND MOT
16VMOT

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 NumberPin Name
15GND MOT
16VMOT

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 NumberPin Name
2M0
3M1
4M2

For selecting any particular step resolution proper logic levels are needed to be maintained on the above-mentioned micro step selection pins.

M0M1M2Microstep Resolution
LowLowLowFull step
HighLowLowHalf step
LowHighLow1/4 step
HighHighLow1/8 step
LowLowHigh1/16 step
HighLowHigh1/32 step
LowHighHigh1/32 step
HighHighHigh1/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 NumberPin Name
7STEP
8DIR

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 NumberPin Name
1EN(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 NumberPin Name
5SLP(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 NumberPin Name
6RST(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 NumberPin Name
10Fault

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 NumberPin Name
12A1
11A2
13B1
14B2

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

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 –

  1. It supports Acceleration and Deceleration.
  2. Supports Stepper drivers.
  3. Very slow speeds are also supported.
  4. Extensive Application Protocol Interface(API).
  5. Supports Subclass.
  6. Supports 2, 3, and 4 wire steppers and 3 and 4 wire half steppers.
  7. 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?

  1. Open your Arduino IDE.
  2. Head to the sketch menu.
  3. Click on include library.
  4. Then click on manage libraries.
  5. Search AccelStepper in the search bar.
  6. 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.

Leave a Comment