Control NEMA 17 Stepper Motor With A4988 Driver and Arduino

by RonFrtek in Circuits > Arduino

406 Views, 3 Favorites, 0 Comments

Control NEMA 17 Stepper Motor With A4988 Driver and Arduino

Control NEMA 17 Stepper Motor With A4988 Driver and Arduino

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

Watch the video!

What You Will Need

A4988 expansion board drv 8825 stepper motor.jpeg
VisuinoAdvrtisementPLCXPertTinyLab (1).jpg
power-supply.png
F5OFEUQJJ4ZYFKY.LARGE.jpg
  • Arduino UNO (Or any other Arduino)
  • Stepper motor NEMA 17
  • A4988 Stepper Motor Driver or (DRV8825)
  • Optional DRV8825/A4988 Stepper Driver Expansion Module
  • Jumper wires
  • Breadboard
  • Power Supply 12V
  • Visuino program: Download Visuino


Brought by PCBWay

2022-08-26_13-41-18.jpg

Thank you PCBWay for supporting this tutorial and helping users learn more about electronics.

What I like about the PCBWay is that you can get 10 boards for approximately $5 which is really cost effective for professional made boards, not to mention how much time you save!

Go check them out here. They also offer a lot of other stuff in case you might need it like assembly3D printingCNC machining and a lot more.

The Circuit

2023-01-18_21-14-58.png
2023-01-18_21-06-20.png
  • Arduino Digital Pin 2 will be used for Steps
  • Arduino Digital Pin 3 will be used for Motor Direction

If using a Stepper Motor Driver Shield:

  • Connect Motor Shield GND pin to Arduino negative pin [GND]
  • Connect Motor Shield [5V] pin to Arduino positive pin [5V]
  • Connect Motor Shield GND pin to Power Supply negative pin [GND]
  • Connect Motor Shield [9V] pin to Power Supply positive pin [+]
  • Connect Motor Shield pin[S] to Arduino digital pin [2]
  • Connect Motor Shield pin[D] to Arduino digital pin [3]
  • Connect stepper motor as shown on the picture.


If using a Stepper Motor Driver 8825:

  • Connect DRV8825 GND pin to Arduino negative pin [GND]
  • Connect DRV8825 DIR pin to Arduino digital pin [3]
  • Connect DRV8825 STEP pin to Arduino digital pin [2]
  • Connect Power Supply for the motor to DRV8825 VMOT and GND
  • Connect Capacitor across VMOT and GND
  • Connect stepper motor as shown on the picture.


Start Visuino, and Select the Arduino UNO Board Type

select-board-uno.jpg
Visuino-Select-Board-UNO.jpg

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 on Picture 2

In Visuino Add Components

2023-01-09_11-50-11.png
2023-01-09_11-51-40.png
2023-01-09_11-52-05.png
2023-01-09_11-53-00.png
2023-01-09_11-53-32.png
2023-01-09_11-54-01.png

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 Set Components

2023-01-09_11-56-36.png
2023-01-09_11-57-22.png
2023-01-09_11-57-41.png

How to set the amount 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 Connect Components

2023-01-09_12-13-07.png
stepper.png

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]

Generate, Compile, and Upload the Arduino Code

Visuino-Compile-UNO.jpg

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.

Play

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

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