Move a Stepper Motor NEMA 17 to an Exact Position With a Button

by RonFrtek in Circuits > Arduino

427 Views, 1 Favorites, 0 Comments

Move a Stepper Motor NEMA 17 to an Exact Position With a Button

Move a Stepper Motor NEMA 17 to an Exact Position With a Button

In this tutorial we will learn how to move a stepper motor NEMA 17 for a certain amount of steps, and then with a push of a button repeat it again.

Watch the Video!

What You Will Need

A4988.png
NEMA17.jpg
A4988 expansion board drv 8825 stepper motor.jpeg
arduino-button.png
resistor-1k-ohm-14w-5.jpg
breadboard.png
VisuinoAdvrtisemenESPNowESP32C3-1.jpg
power-supply.png
arduino.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
  • Breadboard
  • 1K ohm resistor
  • Button
  • 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-02-28_19-36-47.png
2023-02-28_20-20-32.png
  • Arduino Digital Pin 2 will be used for Steps
  • Arduino Digital Pin 3 will be used for Motor Direction

Connecting Button:

  • Connect Arduino Digital pin [7] to button on the breadboard and to the Resistor
  • Connect other side of the resistor to the breadboard pin [GND]
  • Connect Other pin of the button to the breadboard positive pin [5V]
  • Connect Arduino pin [5V] to breadboard positive pin [Red line]
  • Connect Arduino pin [GND] to breadboard negative pin [Black line]


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

FD9ZV5DKU43CVCH.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-45-26.png
2023-02-28_19-46-39.png
2023-02-28_19-47-02.png
2023-02-28_19-47-56.png
  • Add "Debounce Button" component
  • Add "Counter" component
  • Add "Pulse Generator" component
  • Add "Unsigned To Digital" component


In Visuino Set Components

2023-02-28_19-49-53.png
2023-02-28_19-56-26.png
2023-02-28_19-58-03.png
2023-02-28_20-03-30.png
  • 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
  • Select "UnsignedToDigital1" and in the properties window set "Output Pins" to 1
  • Select "Counter1" and in the properties window set "Initial Value" to 5000 << this will be the amount of steps of the stepper motor, you can adjust it to your needs
  • Select "Counter1" and in the properties window set "Max">"Value" to 5000 << this will be the amount of steps of the stepper motor, you can adjust it to your needs
  • Select "Counter1" and in the properties window set "Max">"Roll Over" to False
  • Select "Counter1" and in the properties window set "Min">"Roll Over" to False
  • Select "Counter1" and in the properties window set "Max">"Value" to 0
  • Double click on the "Counter1" and in the Elements window Drag "Set Value" to the Left side
  • Close the Elements window

In Visuino Connect Components

2023-02-28_20-04-35.png
nema17-stepper.png
  • Connect "PulseGenerator1" Pin[Out] to "Counter1" Pin [In]
  • Connect Arduino Board Digital Pin [7] to "Button1" Pin [In]
  • Connect "Button1" Pin [Out] to "Counter1" > 'Set Value 1" Pin [In]
  • Connect "Counter1" Pin [Out] to "UnsignedToDigital1" Pin [In]
  • Connect "UnsignedToDigital1" 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 it will stop, if you press the button again it will run again for a certain amount of steps.

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