Stepper Motor With Arduino and Driver A4988

Published

Introduction: Stepper Motor With Arduino and Driver A4988

About: Do you like technology? Follow my channel on Youtube and my Blog. In them I put videos every week of microcontrollers, arduinos, networks, among other subjects. New tutorials on Tuesdays and Fridays.

Today, I will show a step motor driver. To be more specific, in this video, we are going to deal with the A4988 Driver, but I intend to soon talk more about the similar but more recent DRV8825. Through these two models, you will begin to enter the world of real mechatronics, real robotics, where you steer the stepper motor accurately and forcefully. At this moment, you are entering this new world. I'm going to start recording several videos showing professional mechatronics. I will show the ball spindle, a series of devices, and then you can combine all of this material to make your own CNC machine.

But concerning the assembly today, the stepper motor is connected on the A4988 Driver, using only two Arduino Uno pins. For those who are frustrated because I typically only talk about ESP, well today I'm using the Arduino Uno! I've set up an adjustable source just to give me the voltage for the DC motor.

So this is all. We use an electronic component, such as a 220uF electrolytic capacitor, our driver and Nema 17, which is the motor, and it’s widely used. It may be the most used in 3D printers.

Step 1: Datasheet

I have here the datasheet of the Arduino Uno, and also the datasheet of the A4988. The second has the same pinning as the DRV8825. The difference is that when inserted into the plate, it is necessary to invert the top part, since both have potentiometers, but on different sides.

The A4988 Driver is very cool, as it works with both 3v3 and 5 volts. You can also use ESP. It has two tensions. One powers its internal microcontroller, and also the voltage it uses for the motor that goes up to 35 volts per 2A of maximum current per phase or continuous current per 1A phase. The minimum operating voltage is usually 8 volts. It has several step modes, but today, we will choose to do the "Full" mode. Soon, I’ll make another video detailing the other features of this driver.

As for the A4988 pinout, it has the motor power, the logic power, the connection connections of the coils, and then I also have the operating modes: Reset, Sleep, which we will not get into today, and also the Step and Dir, which will be connected to Arduino Uno.

Step 2: Nema 17

Who doesn’t have Nema 17 can use another one as long as it is Bipolar. In this case, the unipolar motor doesn’t work. It has to be the four-wire bipolar. The electrolytic capacitor used is a simple, passive component.

Step 3: Assembly

In the video, I show the layout scheme on the protoboard. For questions concerning the pinning, just look at the datasheet of the A4988. In my case, to not use 5 volts, I connected the Arduino directly to my computer.

Step 4: A4988 Step Driver

This component, the A4988, has a Trimpot, which is a kind of very small potentiometer. You will need to regulate this device. How? With the following equation:

VRef = Lc x 8 x Rs

The VRef is the reference voltage.

Rs: value corresponding to the plate resistors. See in table:

To make it easier, I have here the calculator that will automatically calculate the reference voltage for you on www.fernandok.com: CALCULATOR

Step 5: A4988 Step Driver

As for the component, we have the potentiometer that can only be controlled with a very small Philips switch. There are also two SMD components, which are resistors. They indicate R100, which is the nomenclature, indicating that the value of it is 0.1.

In the video , I show an example:

We don’t have very high accuracy in this current value, but it works to limit the current on the motor. I have to do this because when using a smaller motor without limiting the current, you run the risk of burning the equipment.

Step 6: Example

In our example in the video, we do a full 200-step cycle in one direction, and then we do two complete cycles of 400 steps. It is important to remember that each step is 1.8 degree, which are 200 steps and enough to take a full turn. We work with the engine in Full Step Mode.

In the assembly, the Arduino Uno is connected to the A4988 driver, which is connected to the stepper motor as a result, and is already working because our program is in Loop. It generates a loop of 200 steps to one side, and 400 steps to the other. I fed the source with 12 volts, and it shows the current that is consuming the circuit. Thus, you can see that with 12 volts, the driver is pulling around 200 milliampere.

Step 7: Code

We begin by defining the constants we use to indicate the driver STEP and DIR pins. Then in the SETUP function, we will set them as output pins.

// define números de pinos do driver no arduino
const int stepPin = 3; const int dirPin = 4; void setup () { // Define os dois pinos como Saídas pinMode (stepPin, OUTPUT); pinMode (dirPin, OUTPUT); }

Loop

In the loop () function, we will make the calls to rotate the motor. First a 200 iteration session to spin 1 complete cycle in one direction, then 400 to spin 2 complete cycles in the opposite direction.

void loop() {
// permite que o motor se mova em uma direção particular digitalWrite(dirPin, HIGH); // faz 200 pulsos para fazer uma rotação de ciclo completo for(int x = 0; x < 200; x++) { digitalWrite(stepPin,HIGH); delayMicroseconds(500); digitalWrite(stepPin,LOW); delayMicroseconds(500); } delay(1000); //1 segundo de delay para inverter a direção

Below, we see the continuation of the loop () function, where we will do 2 complete cycles with the motor.

//Muda a direção da rotação
digitalWrite(dirPin,LOW); // faz 400 pulsos para fazer duas rotações de ciclo completo for(int x = 0; x < 400; x++) { digitalWrite(stepPin,HIGH); delayMicroseconds(500); digitalWrite(stepPin,LOW); delayMicroseconds(500); } delay(1000); //1 segundo de delay para inverter a direção

Share

    Recommendations

    • Clocks Contest

      Clocks Contest
    • Oil Contest

      Oil Contest
    • Water Contest

      Water Contest

    Discussions