Friday, October 25, 2019

Circuit diagram to control Nema 17 stepper motor

Circuit diagram to control stepper motor Nema 17 with Arduino is given in the above image. As A4988 module has a built-in translator that means we only need to connect the Step and Direction pins to Arduino. Step pin is used for controlling the steps while the direction pin is used to control the direction. Stepper motor is powered using a 12V power source, and the A4988 module is powered via Arduino. Potentiometer is used to control the direction of the motor.

If you turn the potentiometer clockwise, then stepper will rotate clockwise, and if you turn potentiometer anticlockwise, then it will rotate anticlockwise. A 47 µf capacitor is used to protect the board from voltage spikes. MS1, MS2, and MS3 pins left disconnected, that means the driver will operate in full-step mode.


Circuit diagram to control Nema 17 stepper motor


Complete connections for Arduino Nema 17 A4988 given in below table.

S.NO.

A4988 Pin

Connection

1

VMOT

+ve Of Battery

2

GND

-ve of Battery

3

VDD

5V of Arduino

4

GND

GND of Arduino

5

STP

Pin 3 of Arduino

6

DIR

Pin 2 of Arduino

7

1A, 1B, 2A, 2B

Stepper Motor



Code Explanation
Complete code with working video control Nema 17 with Arduino is given at the end of this tutorial, here we are explaining the complete program to understand the working of the project.

First of all, add the stepper motor library to your Arduino IDE. You can download the stepper motor library from here.

After that define the no of steps for the NEMA 17.  As we calculated, the no. of steps per revolution for NEMA 17 is 200.

#include <Stepper.h>
#define STEPS 200


After that, specify the pins to which driver module is connected and define the motor interface type as Type1 because the motor is connected through the driver module.

Stepper stepper(STEPS, 2, 3);
#define motorInterfaceType 1


Next set the speed for stepper motor for sale using stepper.setSpeed function. Maximum motor speed for NEMA 17 is 4688 RPM but if we run it faster than 1000 RPM torque falls of quickly.

void setup() {
    stepper.setSpeed(1000);


Now in the main loop, we will read the potentiometer value from A0 pin. In this loop, there are two functions one is potVal, and the other is Pval. If the current value, i.e., potVal is higher than the previous value, i.e., Pval than it will move ten steps in the clockwise direction and if the current value is less than previous value than it will move ten steps in the counter-clockwise direction.

potVal = map(analogRead(A0),0,1024,0,500);
  if (potVal>Pval)
      stepper.step(10);
  if (potVal<Pval)
      stepper.step(-10);

Pval = potVal;


Now connect the Arduino with your laptop and upload the code into your Arduino UNO board using Arduino IDE, select the Board and port no and then click on the upload button.

Now you can control the direction of Nema17 stepper motor using the potentiometer. The complete working of the project is shown in the video below. If you have any doubts regarding this project, post them in the comment section below. 

Code
#include <Stepper.h>
#define STEPS 200

// Define stepper motor connections and motor interface type. Motor interface type must be set to 1 when using a driver
Stepper stepper(STEPS, 2, 3); // Pin 2 connected to DIRECTION & Pin 3 connected to STEP Pin of Driver
#define motorInterfaceType 1
int Pval = 0;
int potVal = 0;

void setup() {
  // Set the maximum speed in steps per second:
  stepper.setSpeed(1000);
}
void loop() {

  potVal = map(analogRead(A0),0,1024,0,500);
  if (potVal>Pval)
      stepper.step(10);
  if (potVal<Pval)
      stepper.step(-10);

Pval = potVal;

}

http://www.apsense.com/user/yinweikou/have?id=159333


No comments:

Post a Comment

Motion Controller and Driver Selection Tips You Should Know

Motion Controller The first thing that should be checked when selecting a motion controller is compatibility with other system components ...