Stepper Stopping after 32xxx steps

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?

#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(pump, OUTPUT);


void  loop()

 if (analogRead(button)>1100)
 digitalWrite (cap,HIGH);
 digitalWrite (vice, HIGH);
 digitalWrite(pump, HIGH);
 digitalWrite (cap,LOW);
 digitalWrite(raise, HIGH);
 digitalWrite(raise, LOW);
 digitalWrite(vice, LOW);
 delay(time); //change this value to adjust the speed
 stepperAngle = stepperAngle+40;



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.


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.


int count = 0;


long count = 0L;

And change stepperAngle from float to long too.