Maker.io main logo

Control NEMA 17 Stepper Motor With A4988 Driver and Arduino

2026-05-18 | By Ron Cutts

License: GNU Lesser General Public License I2C / TWI Microcontrollers Motors Arduino ESP32

In this tutorial, we will use a stepper driver A4988, a NEMA17 stepper motor, an Arduino Uno, and Visuino to run a stepper motor for a certain number of steps.

Watch the video!

Learn more about Visuino: What is Visuino

What You Will Need

What You Will Need

What You Will Need photo 2

What You Will Need photo 3

What You Will Need photo 4

The Circuit

  • Arduino Digital Pin 2 will be used for the steps

  • Arduino Digital Pin 3 will be used for Motor Direction

If using a Stepper Motor Driver Shield:

  • Connect the Motor Shield GND pin to the Arduino negative pin [GND]

  • Connect the Motor Shield [5V] pin to the Arduino positive pin [5V]

  • Connect the Motor Shield GND pin to the Power Supply negative pin [GND]

  • Connect Motor Shield [9V] pin to Power Supply positive pin [+]

  • Connect the Motor Shield pin[S] to the Arduino digital pin [2]

  • Connect the Motor Shield pin[D] to the Arduino digital pin [3]

  • Connect the stepper motor as shown in the picture.

If using a Stepper Motor Driver 8825:

  • Connect the DRV8825 GND pin to the Arduino negative pin [GND]

  • Connect the DRV8825 DIR pin to Arduino digital pin [3]

  • Connect the DRV8825 STEP pin to Arduino digital pin [2]

  • Connect the Power Supply for the motor to the DRV8825 VMOT and GND

  • Connect the Capacitor across VMOT and GND

  • Connect the stepper motor as shown in the picture.

The Circuit

The Circuit photo 2

Start Visuino, and Select the Arduino UNO Board Type

Start Visuino as shown in the first picture. Click on the "Tools" button on the Arduino component (Picture 1) in Visuino. When the dialog appears, select "Arduino UNO" as shown in Picture 2

Start Visuino, and Select the Arduino UNO Board Type

Start Visuino, and Select the Arduino UNO Board Type photo 2

In Visuino, Add Components

Add "Counter" component

Add "Compare Integer Range" component

Add "Pulse Generator" component

Add "Digital Multi Source" component

Add "Toggle(T) Flip-Flop" component

Add "Digital (Boolean) Value" component

In Visuino Add Components

In Visuino Add Components photo 2

In Visuino Add Components photo 3

In Visuino Add Components photo 4

In Visuino Add Components photo 5

In Visuino Add Components photo 6

In Visuino Set Components

How to set the number of steps, for example, 20000 steps:

  • Select "CompareRange1" component and in the properties set "Include Limits" to True and "Range" > "Max" to 20000

This means that as long as the number is within the range of 20000, the Motor should run

How to set the Motor Direction:

  • To set the motor direction, the "Value" of the "DigitalValue1" in the properties window should be either True or False

How to set the Motor Speed:

  • Select "PulseGenerator1" and in the properties window set "Frequency" to 1200 or less. You can set it to a higher number, but the motor might have problems spinning at that speed

  • Select "PulseGenerator1" and in the properties window select "Enabled" and click on the Pin Icon and select Boolean SinkPin

In Visuino Set Components

In Visuino Set Components photo 2

In Visuino Set Components photo 3

In Visuino Connect Components

Connect "Counter1" Pin [Out] to "CompareRange1" Pin [In]

Connect "CompareRange1" Pin[Out] to "PulseGenerator1" Pin [Enabled]

Connect "PulseGenerator1" Pin[Out] to "DigitalMultiSource1" Pin [In]

Connect "DigitalMultiSource1" Pin[0] to "TFlipFlop1" Pin [Clock]

Connect "DigitalMultiSource1" Pin[1] to "Counter1" Pin [In]

Connect "TFlipFlop1" Pin[Out] to Arduino Board Digital Pin [2]

Connect "DigitalValue1" Pin[Out] to Arduino Board Digital Pin [3]

In Visuino Connect Components

In Visuino Connect Components photo 2

Generate, Compile, and Upload the Arduino Code

In Visuino, at the bottom, click on the "Build" Tab, make sure the correct port is selected, then click on the "Compile/Build and Upload" button.

Generate, Compile, and Upload the Arduino Code

Play

If you power the Arduino module, the motor will start to run, and when it reaches a certain number of steps, it will stop.

Congratulations! You have completed your project with Visuino. Also attached is the Visuino project that I created for this. You can download it here and open it in Visuino: https://www.visuino.eu

Downloads

Have questions or comments? Continue the conversation on TechForum, DigiKey's online community and technical resource.