Stepper Stopping after 32xxx steps

Hi
I have a process that requires a stepper to move 40 steps in each loop.
the way I have it set up the arduino adds 40 steps to the target position each time through the loop the moves to the target position.
this works great until it gets to 32 thousand and then it can’t add the 40 more for some reason.
I think I read somewhere this was the biggest number arduino could store in one byte or something (can’t remember specifics)
so how can i work around this?
Thanks

*/
#include <LiquidCrystal.h>
#include <AccelStepper.h>
AccelStepper stepper(1,3,2); //stepper pins

LiquidCrystal lcd(8, 9, 4, 5, 6, 7);//lcd pins
//initialise Outputs
const int buttonPin = 22;
const int pumped = 48;
const int lowered = 47;
int rotate = 25;  //valve 5 blue  t7
int raise = 26;   //valve 4 green  t6
int vice = 1;   //valve 3 yellow t5
int cap = 12;     // valve 2 orange t4
int pump = 4;    // red t3
int led = 13;
float stepperAngle = 0;    //variable for stepper angle
int count = 0;         //Steps count
int buttonState=0;
int time=1000;
int button=A0;
int whichButton=0;

void setup()
{
 pinMode(rotate, OUTPUT);
 pinMode(raise, OUTPUT);
 pinMode(vice, OUTPUT);
 pinMode(cap,OUTPUT); 
 pinMode(pump, OUTPUT);
 pinMode(led,OUTPUT);
 stepper.setMaxSpeed(30);
 stepper.setAcceleration(100);
 stepper.setCurrentPosition(0);
 lcd.begin(16,2);
 lcd.clear();
 lcd.print("STEPS");
 lcd.setCursor(0,1);
 lcd.print("ANGLE");

}

void  loop()

{
 
 if (analogRead(button)>1100)
 {
  stepperAngle=(0);
 }
 digitalWrite (cap,HIGH);
 digitalWrite (vice, HIGH);
 digitalWrite(pump, HIGH);
 delay(200);
 digitalWrite(pump,LOW);
 delay(400);
 digitalWrite (cap,LOW);
 delay(700);
 digitalWrite(raise, HIGH);
 delay(150);
 digitalWrite(raise, LOW);
 digitalWrite(vice, LOW);
 delay(time); //change this value to adjust the speed
 stepperAngle = stepperAngle+40;
 stepper.runToNewPosition(stepperAngle);
 
 delay(200);



count=count+1;

lcd.setCursor(7,0);
lcd.print(count);
lcd.setCursor(7,1);
 lcd.print(stepperAngle);
lcd.setCursor(12,1);
lcd.print(whichButton);
}

Filling_Machine_with_stepperand_lcd2.ino (1.58 KB)

You declared x as integer, which stores a 16-bit (2-byte) value. This yields a range of -32,768 to 32,767.
If you would use an unsigned integer: the range is 0 .. 65535.

If you use an unsigned long variable (4-byte), you can count from 0 .. 4,294,967,295 (2^32 - 1).

But: after that number is reached, the stepper will stop again; to avoid that you could define a second variable, say "y", which starts with 1 and when your counter "x" is getting to its limits, you could set it back to 0 and increment y by 1, so you can use the multiplicator y to reach VERY BIG numbers.

BTW:

I think I read somewhere this was the biggest number arduino could store in one byte or something

You could have found the answer yourself by

  1. Search in this forum
  2. Google

Great thanks
I'll try that.
I tried google extensively but I was looking in the wrong area unfortunately.

Change

int count = 0;

to

long count = 0L;

And change stepperAngle from float to long too.