How to Interface Stepper Motor With Arduino and Stepper Motor Driver




Introduction: How to Interface Stepper Motor With Arduino and Stepper Motor Driver

This tutorial is going to teach you some basics on using Stepper Motor while interfacing with Arduino and Stepper Motor Driver.

Step 1: Introduction


Bipolar Stepper Motor is DC motor that move in discrete steps. It has multiple coils that are organized in groups called "phases". By energizing each phase in sequence, the motor will rotate, a step at a time. In order to be able to move the motor, you will need a motor driver. Thus, stepper motor driver A4988 is designed to play this role. A4988 stepper motor driver comes with heat sink. This stepper motor driver lets you control one bipolar stepper motor at up to 2 A output current per coil.

Specificaations of Bipolar Stepper Motor:

  • Origin: China
  • Model: 42HD04
  • Low cost, small size
  • Bipolar
  • 4 lead wire
  • 1.8 deg/ step
  • Torque:
  • Size: 33mm x 42mm x 42mm
  • Voltage being applied and test: 6V to 12V

Specifications of Stepper Motor Driver A4988:

  • Simple step and direction control interface
  • Five different step resolutions: full-step, half-step, quarter-step, eight-step, sixteen-step
  • Adjustable current control lets you set the maximum current output with a potentiometer which lets you use voltage above your stepper motor's rated voltage to achieve higher step rates.
  • Intelligent chopping control that automatically selects the correct current decay mode (fast decay or slow decay)
  • Over-temperature thermal shutdown, under-voltage lockout, and crossover-current protection
  • Short-to-ground and shorted-load-protection
  • Dimension: 20mm x 15mm x 10mm

Step 2: Pin Definition

Step 3: Sample Hardware Installation

Step 4: Sample Source Code

To get the result, please download the sample source code attached below and upload it into Arduino.

Step 5: Procedure (1)

This example is done by driving the 42 Step Stepper Motor device using the Arduino UNO via A4988 Stepper Motor Driver Module. Before connecting the motor power supply to the module, the sample source code must be uploaded first into the Arduino UNO board via USB 2.0 type A male to type B male cable.

Step 6: Procedure (2)

Next, adjust the current limiting of the driver by using the potentiometer on board. This is to make sure that the current is within the current limits of the motor ranges from 0mA to 2000mA (2A).

In order to prevent damage to both of the motor and driver module, the current must actively be limited to under 1A. In full step mode, the current through the coils is limited to 70% of the current limit, so to get a full-step coil current of 1 A, the current limit should be 1 A/0.7=1.4 A, which corresponds to a Vref of 1.4 A/2.5=0.56 V. Please refer to the A4988 datasheet for more information. The current limit relates to the reference voltage is as follow:

Current Limit = Vref / (8 x Rs)

  • Rs = Sense Resistor
  • Vref = input voltage on the REF pin.

Because of different stepper motor has their own specification, so please check the motor’s datasheet for the current settings. In this example, the Vref (voltage references) is set to about 0.4 V, so the current limit is 1 A. You can measure the Vref of the module by attaching the multimeter probes between the center of the potentiometer and the ground pin that is connected to the Arduino board.

Step 7: Procedure (3)

The USB cable that is used to upload the source code can now be disconnected. Next, connect the motor power supply (Li-on Battery, 7.4 V, 1200mAh) to the module through the power jack. The stepper motor will start to rotate clockwise and anticlockwise according to the given sample source code.

Step 8: Video

Be the First to Share


    • Pets Challenge

      Pets Challenge
    • Build a Tool Contest

      Build a Tool Contest
    • Backyard Contest

      Backyard Contest



    5 years ago

    hi everyone
    my stepper motor gives whistle voice during rotation.
    Who knows what the problem is?
    my stepper motor is 42BYGH40388


    5 years ago

    I'll echo the other commenters--that's way too much power to apply to the Vin of the Arduino. I'd suggest running a buck converter or similar from the motor power to the Arduino Vin and ground. You can get a 12v buck converter from EBay for just a couple dollars. I bought a 10-pack because I end up using one for almost every project.


    6 years ago

    The Arduino website reference page states that the maximum voltage to be applied to the Vin pin is 20 volts, but the recommended maximum is listed as 12 volts. Therefore, 35 volts will more than likely fry your Arduino or burn out the voltage regulator circuit. Good idea though to teach others how to attach a stepper to the Arduino. I find that a lot of people are completely in the dark when it comes to step motors. The step motor simply will not run if you attach voltage to two wires like other small motors, so many people just leave them alone. They are missing a lot of great uses for steppers so perhaps your tutorial will help some fellow enthusiasts to learn to use step motors. Kudos to you.


    6 years ago

    You are showing 8-35v going to the driver and to the Arduino. 35v seems a bit high for the Arduino. Might put a warning label on your wiring schematic to limit voltage to 16v if using this arrangement. Otherwise, I like your project.


    6 years ago

    Hi, Thanks for your comment. the power of arduino is separate with the power of motor driver. The 8V to 35V is connecting to motor driver only. ^^