NEMA 17 Stepper Motor Set Sequence of Steps, Speed & Direction With A4988 Driver and Arduino

by RonFrtek in Circuits > Arduino

273 Views, 1 Favorites, 0 Comments

NEMA 17 Stepper Motor Set Sequence of Steps, Speed & Direction With A4988 Driver and Arduino

NEMA 17 Stepper Motor Set Sequence of Steps, Speed & Direction With A4988 Driver and Arduino

In this tutorial we will learn how to set a sequence of steps and direction for the stepper motor NEMA 17 and repeat them in a loop.

Watch the Video!

What You Will Need

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


Brought by PCBWay

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

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

NEW! Now you can get Aluminum PCB & FLEX PCB in their Special Offer!

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.

Circuit

2023-03-12_13-51-52.png
2023-03-12_13-50-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-02-28_19-46-39.png
2023-02-28_19-47-02.png
2023-02-28_19-47-56.png
2023-03-12_14-05-06.png
2023-03-12_14-05-38.png
2023-03-12_14-06-30.png
  • Add "Counter" component
  • Add "Pulse Generator" component
  • Add "Unsigned To Digital" component
  • Add "Integer Value" component
  • Add "Sequence" component
  • Add "Digital (Boolean) Value" component

In Visuino Set Components

2023-03-12_14-08-55.png
2023-03-12_14-14-25.png
2023-02-28_19-56-26.png
2023-02-28_19-49-53.png
2023-03-12_14-19-32.png
2023-03-12_14-19-53.png
2023-03-12_14-20-07.png
2023-03-12_14-20-22.png
2023-03-12_14-23-40.png
2023-03-12_14-25-37.png
2023-03-12_14-27-20.png
2023-03-12_14-29-02.png
2023-03-12_14-29-19.png
  • Select "Counter1" and in the properties window select "Max" > "Value" and click on the Pin Icon and select "Integer SinkPin"
  • Select "Counter1" and in the properties window set "Max" > "Value" to 0 and "Roll over" to False
  • Select "Counter1" and in the properties window set "Min" > "Value" to 0 and "Roll over" to False
  • Select "UnsignedToDigital1" and in the properties window set "Output Pins" to 1
  • Select "PulseGenerator1" and in the properties window set "Frequency" to 2000 << this will be the speed of the stepper motor, you can adjust it to your needs

Setting the steps:

  • Double click on the "IntegerValue1" and in the Elements window drag "Set Value" to the left side and in the properties window set "Value" to 1000
  • drag another "Set Value" to the left side and in the properties window set "Value" to 800
  • drag another "Set Value" to the left side and in the properties window set "Value" to 3000
  • Close the Elements window

Setting the direction:

  • Double click on the "DigitalValue1" and in the Elements window drag "Set Value" to the left side
  • drag another "Set Value" to the left side and in the properties window set "Value" to True
  • Close the Elements window

Setting the Sequence:

  • Select "Sequence1" and in the properties window set "Repeat" to True
  • Double click on the "Sequence1" and in the Elements window drag "Period" to the left side
  • drag another "Period" to the left side and in the properties window set "Delay" to 2000
  • drag another "Period" to the left side and in the properties window set "Delay" to 2000
  • Close the Elements window


In Visuino Connect Components

2023-03-12_14-37-22.png
nema17-sequence.png
  • Connect "Sequence1" > "Period1" pin [Out] to "DigitalValue1" > "Set Value1" pin [In]
  • Connect "Sequence1" > "Period1" pin [Out] to "IntegerValue1" > "Set Value1" pin [In]
  • Connect "Sequence1" > "Period2" pin [Out] to "DigitalValue1" > "Set Value2" pin [In]
  • Connect "Sequence1" > "Period2" pin [Out] to "IntegerValue1" > "Set Value2" pin [In]
  • Connect "Sequence1" > "Period3" pin [Out] to "DigitalValue1" > "Set Value1" pin [In]
  • Connect "Sequence1" > "Period3" pin [Out] to "IntegerValue1" > "Set Value3" pin [In]


  • Connect "PulseGenerator1" Pin[Out] to "Counter1" Pin [In]
  • Connect "IntegerValue1" Pin [Out] to "Counter1" Pin [Reset]
  • Connect "IntegerValue1" Pin [Out] to "Counter1" > 'Max > Value" Pin [In]
  • Connect "Counter1" Pin [Out] to "UnsignedToDigital1" Pin [In]
  •  Connect "UnsignedToDigital1" Pin [Out] to Arduino Board Digital Pin [2]
  •  Connect "DigitalValue1" Pin [Out] to Arduino Board Digital Pin [2]



Generate, Compile, and Upload the Arduino Code

FBR42I2KXBU01YW.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 and press the button the motor will do will start to run and when it reaches a certain amount of steps in our case 1000 it will change the direction and do 800 steps and after that change the direction again and do a 3000 steps. Because we set the Sequence component Repeat to True, the motor will continue to do this in a loop.

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