• Worldwide Shipping

  • 24/7 Customer Support

  • FAQ
  • Worldwide Shipping

  • 24/7 Customer Support

  • FAQ

HUM: A4988 stepper motor driver

You are a beginner with Croduino. Or electronics? A specific module caught your eye, but you do not know how to use it? Do not worry, HUM is here for you! How to Use Module (HUM) is a blog tutorials series by e-radionica where you will find all you need in order to begin working with your favorite module. Tutorials include: technical characteristics, work principle, instructions on how to connect the module with Croduino and the basic code. Everything else is left to your imagination.

INTRODUCTION

When we want to control a step motor using Croduino, we must have a driver that is connected between the motor and Croduino. The reason why we have to use the driver is the current the motor uses when operating and it is always higher than the current Croduino provides at its outputs. The A4988 module is used with bipolar step motors and allows us easier guidance as it has a built-in translator that manages when to turn an individual motor coil on. This module uses specific power supply for the logical part and a specific power supply for the step motor, since the motors require a voltage higher than 5 volts which are used by the logical part of the module. It also includes protection against excessive current, thus providing us with safe operation.

Module characteristics:
• Logical part voltage: 3.3 V ili 5 V
• Motor voltage: 8-35 V
• Maximum motor current: 2 A

HOW DOES THE MOTOR WORK?

The A4988 stepper motor driver has a translator that facilitates the usage. When impulses are connected to the driver's STEP pin, the driver monitors the coil which is to be connected to the power supply and how it should be connected (which end to the positive pole of the power supply and which to the negative pole of the power supply) using the translator and logic controller, and depending on the number of impulses, the motor makes the same number of steps. As the driver determines everything, we need to send the impulse of how many steps we want the motor to make on the STEP pin. The DIR pin is used to determine the direction of rotation of the motor and it can be set to HIGH or LOW, depending on the desired direction. Inside the driver are mosfet transistors that allow the driver to deliver up to 2 A current per coil, and we have the protection against excessive current that can be adjusted with a trimmer potentiometer depending on how much current we need for our motor.

This driver also has a micro-step function that allows dividing the number of steps into smaller parts. That is, if we have a motor that takes 200 steps in a single turn, with this function we can achieve more steps, i.e. to achieve a higher resolution of the motor. This way we have the whole step, 1/2, 1/4, 1/8, 1/16 of the step. When using this function, we need to know that, in this case, the motor will take more steps in a single turn and it will also take longer. If we use the micro-step function, depending on how we want to divide the motor step, we need to connect the pins MS1, MS2, MS3 according to the given table, if we want the driver to work properly without dividing the motor steps into micro-steps, we do not connect the pins MS1, MS2, MS3 and then we achieve the whole step.

HOW TO CONNECT IT?

Connecting the A4988 driver is easy, we need to connect the power supply to the logical part for which we can use 5 V from the Croduino, we also need a power supply whose voltage meets the needs of the motor, but it must be more than 8 V. We connect the motor to the outputs of the driver, and to STEP and DIR pins we connect the digital pins of the Croduino using which we want to control the motor. A full-circuit wiring scheme is shown below, where Croduino is used for logical power supply and a 12 V adapter for power supply of the motor.

CRODUINO CODE

This driver is easy to program and we do not need a library to use it, we simply have DIR and STEP pins to control the motor. We set the DIR pin to HIGH or LOW depending on the direction of rotation of the motor and on the STEP pin, we make impulses depending on the number of motor steps. Below, there is a code that moves the motor 200 steps to one side and after a one-second pause to the other.

const int stepPin = 6; //setting the step to digital pin 6
const int dirPin = 5; //setting the dir to digital pin 5
void setup() {
// setting the dir and step pins as output pins
pinMode(stepPin,OUTPUT);
pinMode(dirPin,OUTPUT);
}
void loop() {
digitalWrite(dirPin,HIGH); // setting the dir pin to HIGH, for the motor to rotate in one direction
// Sending 200 impulses to the step pin for the motor to make 200 steps
for(int x = 0; x < 200; x++) {
digitalWrite(stepPin,HIGH); //setting the step pin to HIGH
delayMicroseconds(5000); //setting the width of the HIGH part to 5 ms (the minimun for the driver is 1 us)
digitalWrite(stepPin,LOW); //setting the step pin to LOW
delayMicroseconds(5000); //setiing the width of the LOW part to 5 ms (the minimum for the driver 1 us)
}
delay(1000); // 1 second pause
digitalWrite(dirPin,LOW); //changing the rotation direction
// Sending 200 impulses to the step pin for the motor to make 200 steps
for(int x = 0; x < 200; x++) {
digitalWrite(stepPin,HIGH); //setting the step pin to HIGH
delayMicroseconds(5000); //setting the width of the HIGH part to 5 ms (the minimum for the driver is 1 us)
digitalWrite(stepPin,LOW); //setting the step pin to LOW
delayMicroseconds(5000); //setting the width of the LOW part of the impulse to 5 ms (the minimum for the driver is 1 us)
}
delay(1000); // 1 second pause
}
Leave a Reply