Large Stepper Motor Control A4988

Introduction: Large Stepper Motor Control A4988

About: All what I do I'm doing it for fun 🎩 🎮 My name is Chris, I'm an electronics engineer and a Youtuber who likes : Electrical projects 🔌 3D printing ⚙️ Electronic R&D stuff 🔎 We all know that robots are our …

Hey guys! I Hope you already enjoyed my previous instructable "How to Make a Humanoid Robot". This is an informative tutorial to teach you the basics of any stepper motor control, I already posted a video about controlling speed and direction of DC motors and today we will get started with the stepper motors and hopefully in the next tutorial I will explain how to play a bit with some servomotors.

During the making of this tutorial, we tried to make sure that this instructable will be the best guide for you in order to enjoy learning the basics of stepper motors controlling since this is so important especially for those who want to start electronics and robotics learning. so we hope that this instructable contains the needed documents. What you will learn from this instructable:

  1. Define the stepper motors Uses and Needs.
  2. Understand the Stepper motor mechanism.
  3. Learn the importance of the stepper motor driver A4988.
  4. Make the appropriate wiring diagram with an Arduino board.
  5. Write your first stepper control test.
  6. Start testing and debugging

Step 1: What Are the "stepper Motors"!

A stepper motor, also known as step motor or stepping motor belongs to the brushless DC electric motors with a specificity of dividing a full rotation into a number of equal steps or we better call them equal angles, the motor’s axis position can be controlled to move and hold at these angle without having a feedback sensor, and also due to its high torque capacity this kind of motors could maintain stable the motor axis on hold when it carries a heavy charge.

Talking about the two phase’s stepper motor category we have :

The bipolar motors

Comes with 4 wires to control the coils power polarity

Unipolar motors

That comes with 5 or 6 wires for the control.

Step 2: How the Stepper Motor Works

The coils are used to control the steps performed by the motor following some polarity sequences

A typical driving pattern for a two coils bipolar stepper would be: A+ B+ A− B−

We can define the coils patterns using a millimeter by measuring the resistance between the stepper connection wires, and it should measure some resistance between each two coils ends, please check the photos above.

In order to make the stepper moves, a sequence of power polarity should be sent from a controller through the stepper driver and every time the sequence change the stepper perform a step in a precise direction with a constant speed which is the sequences speed so the faster the sequences move the faster the stepper rotate.

Step 3: The Stepper Driver A4988

Backing to the control driver, basically some transistors to control the current flow through the stepper coils.

In our tutorial we will use the A4988 driver which allows us to easily control direction and speed of the stepper and could provide up to 35V 2Amps output control for the motor, the driver will be connected to an Arduino Nano board which is the heart of our control part.

You can download the driver full datasheet below

Step 4: The Circuit Diagram

Moving the circuit diagram I used EasyEDA platform to create the above schematic (you can have it from the download link PDF Format), EasyEDA will help you to establish your circuit diagram easilly and then convert it in PCB due to its builtin features you can then place and order for your PCB from JLCPCB. by the way guys I invite you to join me in the new community HUB released by JLCPCB for makers in order to more engage the community.

Invitation link :

Backing to our circuit diagram as it shows the photo above we have the Arduino board connected to the stepper motor through the A4988 driver.

About the driver we will need three pins to connect to Arduino which are the Enable, the step and the direction pins.

About the driver output you will connect each pin the appropriate coil end. One important thing is connecting the sleep and reset pins to each other, otherwise the motor will be trembling and won’t move.

Step 5: Codes and Tests

About the control program, no libraries required for this task so just some pinmode() and giditalWrite() functions

First we set the pins and we configure them as OUTPUTs and we set the initial value of the Enable output to LOW to activate the stepper motor driver.

const int EN=2;         //ENABLE PIN
const int Step=3;       // STEP PIN
const int dir=4;        // DIRECTION PIN
/*----------------------------SETUP FUNCTION--------------------------*/
void setup() 
  pinMode(dir,OUTPUT);    // DIRECTION AS OUTPUT
  pinMode(Step,OUTPUT);   // STEP AS OUTPUT
  digitalWrite(EN,LOW);   // SET ENABLE TO LOW

/*----------------------------LOOP FUNCTION--------------------------*/
void loop() 
  for(int x = 0; x < 1000; x++) // LOOP 1000 TIMES FOR 1000 RISING EDGE ON STEP PIN
    digitalWrite(Step,HIGH);    // STEP HIGH
    delay(1);                   // WAIT
    digitalWrite(Step,LOW);     // STEP LOW
    delay(1);                   // WAIT
  delay(10);                    // DELAY BEFOR SWITCH DIRECTION
  for(int x = 0; x < 1000; x++) // LOOP 1000 TIMES FOR 1000 RISING EDGE ON STEP PIN
    digitalWrite(Step,HIGH);    // STEP HIGH
    delay(1);                   // WAIT
    digitalWrite(Step,LOW);     // STEP LOW
    delay(1);                   // WAIT
  delay(10);                    // DELAY BEFOR SWITCH DIRECTION

About the direction pin once we set it to LOW the stepper will move forward and for HIGH the stepper will spin on the backward direction

Now every pulse on the direction pin will push the motor to make a step and in this code our motor will perform 1000 steps forward then it will spin 1000 steps backward.

Do not get confused on steps and full rotation because a step on our motor is a 1.6 degree angle and a full rotation is 360 degrees angle so our stepper will almost spin for 5 rotations in each direction.

After preparing the circuit as it shows the above photo all what it need now is uploading the code, then we plugin the external power supply for the stepper and it should be applied on Vmot input pin.

Do not forget to connect the reset pin and the sleep pin to each other.

Following this tutorial you are now able to control and test your stepper motors coming from electronic devices like 3D printers.

Let me know through the comment section what other tutorials do you want me to make for you, do not forget to thumb this tutorial if you like it and to follow us for more awesome projects.

One last thing, make sure that you are doing electronics every day.
It was BEE MB from MEGA DAS see you next time.
Arduino Contest 2020

Participated in the
Arduino Contest 2020

Be the First to Share


    • Halloween Contest

      Halloween Contest
    • Microcontroller Contest

      Microcontroller Contest
    • Plywood Contest

      Plywood Contest



    Tip 2 years ago

    Nice intro to stepper motors, but the code is not very useful. Using delay() is evil as it blocks the rest of the sketch from running.
    The problem with the example sketch is that it does not let you control the stepper motor speed or position or enter commands to set the position or speed while the motor is running.

    Simple Multitasking in Arduino
    has an example sketch using AccelStepper library that runs the stepper and still leaves the sketch free to do other tasks

    Arduino String Processing for Beginners
    has an example sketch that shows you how to you can processes user commands while still running the rest of the sketch at maximum speed.

    Combining these two instructables with your great intro to stepper motors will give you a stepper motor controller that can be controlled on the fly by the user or other external inputs