Problem with number x for stepper motor

Hey guys and girls!

I have not much experience with programming.
I will explain my problem here and i hope that there is a bright mind that knows what is wrong with it.

First of all i want to explain what i want my programm to do and what i have.

I use Arduino Uno board
cheap chinese stepper motor driver HY DIV258N 5A
Nema 17 stepper motor. 1,8 degrees , up to 3A

I need that motor to rotate how much rotations i want, and so far everything has been fine, but then i had to change my driver settings so it splits signal. Instead of being 1:1 , i wanted it to go to 1:16.

Now this is where i found out my problem.

In the programm there is command for motor and it has X in it.

When my driver settings are set 1:1, my X number was set to 3800 and it was very good for me.
Once i set my driver to 1:2, X number settings have to double, so it would be 7600.
And so it goes till 1:16.

Now for me it makes sense that since its 1:16 all i have to do is multiply 3800x16 and result i enter for X

Unfortunately it doesnt work like that, once i enter 60800, motor spins like forever.

I have tried to enter different numbers and i found out that once i get over like 32000, it starts to behave strangely and just dont stop.

Atm i have driver set to 1:8 and my number is 30400 which seems to cover my distance perfectly.

(int x = 0; x < 60800 ; x++) this is where i have my problem

Here is the code that i am using ( I havent written it myself, i have read many others and kinda adapted it to what i need so dont judge me hard on that :smiley: )

// defines pins numbers
const int stepPin = 4;
const int dirPin = 3;

void setup() {
// Sets the three pins as Outputs
pinMode(stepPin,OUTPUT);
pinMode(dirPin,OUTPUT);
pinMode(7, OUTPUT);

}
void loop() {
delay(230000); // long Break at start
digitalWrite(7, HIGH);
delay(300);
digitalWrite(7, LOW);
delay(2000);

digitalWrite(dirPin,LOW); // Enables the motor to move in a particular direction
for(int x = 0; x < 30400 ; x++) { //3800 1:1, 30400 1:8, ??? 1:16
digitalWrite(stepPin,HIGH);
delayMicroseconds(1000);
digitalWrite(stepPin,LOW);
delayMicroseconds(1000);
}
//delay(2000); // One second delay

delay(2000);
digitalWrite(7, HIGH);
delay(300);
digitalWrite(7, LOW);
delay(2000);

digitalWrite(dirPin,LOW); // Enables the motor to move in a particular direction

for(int x = 0; x < 30400 ; x++) {
digitalWrite(stepPin,HIGH);
delayMicroseconds(1000);
digitalWrite(stepPin,LOW);
delayMicroseconds(1000);
}

delay(2000);
digitalWrite(7, HIGH);
delay(400);
digitalWrite(7, LOW);
delay(230000); //Long pause before direction change

delay(2000);
digitalWrite(7, HIGH);
delay(400);
digitalWrite(7, LOW);
delay(2000);

digitalWrite(dirPin,HIGH); //Changes the rotations direction
// Makes 400 pulses for making two full cycle rotation
for(int x = 0; x < 30400; x++) {
digitalWrite(stepPin,HIGH);
delayMicroseconds(1000);
digitalWrite(stepPin,LOW);
delayMicroseconds(1000);
}

delay(2000);
digitalWrite(7, HIGH);
delay(300);
digitalWrite(7, LOW);
delay(2000);

digitalWrite(dirPin,HIGH); //Changes the rotations direction
// Makes 400 pulses for making two full cycle rotation
for(int x = 0; x < 30400 ; x++) {
digitalWrite(stepPin,HIGH);
delayMicroseconds(1000);
digitalWrite(stepPin,LOW);
delayMicroseconds(1000);
}

delay(2000);
digitalWrite(7, HIGH);
delay(300);
digitalWrite(7, LOW);
delay(2000);

}

an 'int' holds a number in the range -32767...+32766. You are trying to use a number that is outside that range.

Either make it an unsigned int (0..65535) or make it a long int (-2,147,483,648 ... +2,147,483,647)

Thank you! How could i do it? Do i have to make it like int Distance = 60800, and then instead of writing number i type Distance?

(long x = 0; x < 60800 ; x++)

or

(unsigned int x = 0; x < 60800 ; x++)

You have posted code without using code tags. The code tags make the code look

like this

when posting source code files. It makes it easier to read, and can be copied with a single mouse click. Also, if you don’t do it, some of the character sequences in the code can be misinterpred by the forum code as italics or funny emoticons. The “Code: [Select]” feature allows someone to select the entire sketch so it can be easily copied and pasted into the IDE for testing.
If you have already posted without using code tags, open your message and select “modify” from the pull down menu labelled, “More”, at the lower right corner of the message. Highlight your code by selecting it (it turns blue), and then click on the “</>” icon at the upper left hand corner. Click on the “Save” button. Code tags can also be inserted manually in the forum text using the code and /code metatags.

OKay thank you! I cant wait to try it right now!!!