how to increase torque nema 17

guys my name is bruce and i have been working in a project where i have a slider with a belt and a nema 17 motor. i got it to work with no problem but as i start addig weight to the slider the motor starts jumping i think. im not sure but i think it needs more torque.
how can i do that . ?
im going to pase my sketch here please can someone quide me in how to control this better . thank you.


#define SMOOTHSTEP(x) ((x) * (x) * (3 - 2 * (x)))

#include <Wire.h>
#include <stepperUNO.h>
stepMOTOR motor1;

#include <Pushbutton.h>
Pushbutton button1(6);
Pushbutton button2(10);

#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

uint8_t backslash[8] = {
0b00000,
0b10000,
0b01000,
0b00100,
0b00010,
0b00001,
0b00000,
0b00000
};

char spinningTop[] = {'/', '-', 0, '|'};
uint8_t k;

float v = 0.0;
float X = 0.0;
float travel = 9000.0;
float ramp = 300.0;
float motorSpeed = 1500;
int motorSpeedMin = 1500;
int motorSpeedDef = 285; // control the speed of the motor
int motorSpeedMax = 200;
int motorRamp=550;
int spraySpeed=3;

String output = "";
int waitTime = 60;

int lcd_key = 0;
int adc_key_in = 0;

#define btnRIGHT 0
#define btnUP 1
#define btnDOWN 2
#define btnLEFT 3
#define btnSELECT 4
#define btnNONE 5

int read_LCD_buttons(){
adc_key_in = analogRead(0);

if (adc_key_in > 1000) return btnNONE;

if (adc_key_in < 50) return btnRIGHT;
if (adc_key_in < 250) return btnUP;
if (adc_key_in < 450) return btnDOWN;
if (adc_key_in < 650) return btnLEFT;
if (adc_key_in < 850) return btnSELECT;

return btnNONE;
}

const int stepPin = 13;
const int dirPin = 12;
const int enablePin = 11;

void setup() {

motor1.begin(0x4);

motor1.enable();

int waitSelect = 0;

Serial.begin(9600);

pinMode(enablePin, OUTPUT);

k = 0;

pinMode(stepPin,OUTPUT);
pinMode(dirPin,OUTPUT);

lcd.begin(16,2);
lcd.createChar(0, backslash);
lcd.setCursor(0,0);
lcd.print("welcome");
delay(1000);
lcd.setCursor(0,1);
lcd.print("Ready :3");

digitalWrite(enablePin,HIGH);
while(waitSelect==0) {
lcd_key = read_LCD_buttons();
switch (lcd_key){

case btnRIGHT:{
if (spraySpeed < 8) {
spraySpeed = spraySpeed + 1;
motorSpeedMax = motorSpeedMax + 200;
}
delay(100);
break;
}
case btnLEFT:{
if (spraySpeed > 3) {
spraySpeed = spraySpeed - 1;
motorSpeedMax = motorSpeedMax - 200;
}
delay(100);
break;
}
case btnUP:{
waitTime = waitTime + 1;

delay(100);
break;
}
case btnDOWN:{
waitTime = waitTime - 1;

delay(100);
break;
}
case btnSELECT:{
waitSelect = 1;

break;
}
case btnNONE:{

break;
}
}
lcd.setCursor(8,1);
lcd.print(String(spraySpeed));
lcd.setCursor(11,1);
lcd.print(":"+ String(waitTime));
lcd.setCursor(5,1);
lcd.write(spinningTop[k%4]);
k = (k+1) & 0b11;
delay(100);
}
lcd.setCursor(0,1);
lcd.write(" ");
digitalWrite(enablePin,LOW);
}
void loop() {
int waits[300];
for(int x = 0; x < ramp; x++) {
v = x / ramp;
v = SMOOTHSTEP(v);
X = (motorSpeedDef * v) + (motorSpeedMin * (1.0 - v));
waits[x]=X;
}

//digitalWrite(dirPin,HIGH);

motorSpeed = motorSpeedDef;
int countdown = waitTime;
for(int x = 0; x < 300; x++) {
motor1.setDirection(true);
motor1.step();
delayMicroseconds(waits[x]);

}
for(int x = 0; x < travel-600; x++) {

motor1.step();
delayMicroseconds(motorSpeedDef);

}
for(int x = 299; x >= 0; x--) {
motor1.step();
delayMicroseconds(waits[x]);

}

while(countdown>0) {

countdown -= 1;
lcd.setCursor(11,1);
output = String(countdown);
if (output.length()<2) {
output = "0"+output;
}

lcd.print(":"+ output);

if (countdown > 0) {
delay(1000);
}
}

motor1.setDirection(false);
motorSpeed=motorSpeedDef;

for(int x = 0; x < 300; x++) {

motor1.step();
delayMicroseconds(waits[x]);

}
for(int x = 0; x < travel-600; x++) {

motor1.step();
delayMicroseconds(motorSpeedMax);

}
for(int x = 299; x >= 0; x--) {

motor1.step();
delayMicroseconds(waits[x]);

}
delay(1000);
setup();
}

slider.txt (4.47 KB)

Nema 17 just tells us two things

1/ that it follows the "National Electrical Manufacturers Association" standard for motor mounts which is used in the industry to ensure that replacement parts will fit

2/ The NEMA number is related to the diameter of the motor times 10. So a NEMA 17 motor is 1.7 inches around or down the side

So you gave us some mounting information for your motor, but we know nothing about its intrinsic capabilities.

all these for example are NEMA 17

but their holding torque will vary vastly from 0.07Nm to 0.46Nm or similarly for the running torque (see for example this datasheet for those in the picture above)

--> Would be good to find out exactly what's the capability of yours and what torque you see compared to what has been advertised. (also could be interesting to know which Stepper Motor Controller you use and if you can provide enough current)

PS/ there is a smiley with sun glasses and black dots in your code... please use code tags / read how to use the forum

Edit your post and post the code properly, using code tags.

What motor driver are you using? If a bipolar motor, the drv8825 or a4988 drivers are much much better than the ancient L293/298 drivers. And the drv8825 and a4988 will allow running the motors at a higher voltage and setting the current to obtain maximum torque that the motor is capable of.

As requested, please use code tags. Also it would make the code more readable if you use the autoformat tool (Ctrl-T) and remove excessive white space.

im using the StepperUNO is a stepper motor manual control board for standalone system.

http://lechacal.com/wiki/index.php/Stepper_UNO_v1.0

So they are A4988 drivers. Have you set the coil current on the drivers?

im sorry i dont have all the answer for you im super new at this by reading i have done all this in a period of a week. and to answer your question NO i have not mess with the little coil current on the drivers yet . is that something i should be touching .? i thought everything was code but if needed yes i can do that. is there a procedures so i can not mess that up?

If you want to get maximum torque that the motor is capable make sure the current is a safe value for the motor then, yes you need to set the current. You need the motor datasheet to tell you the coil (phase) current of the motor. Then the procedure (in a video) is here.

okis thank you so much im going to hunt to find out where my tech department bought this motor from. and ill get the data sheet and follow your recommendation thank you so much. for your help. :slight_smile: ill keep you guys posted on the results. thank you

These links may help
Stepper Motor Basics
Simple Stepper Code

...R