How do i increment a var value based on a full revolution of my stepper motor?

Hi, i'm working on a project where i have a stepper motor and i want to make 200 full revs(spins)(40,000 steps) and count each time it does a full revolution. The way i would like it to work is; when the stepper does 200 steps it increments the value for the variable "cntsteps".

Right now i'm using a proximity sensor to detect each spin but instead of using the sensor i would like to know if its possible to do what im asking :slight_smile:

anyway here's the code i have for the sensor

/*     Simple Stepper Motor Control Exaple Code
 *      
 *  by Dejan Nedelkovski, www.HowToMechatronics.com
 *  
 */
// defines pins numbers
const int stepPin = 3; 
const int dirPin = 2; 
const int cntsensor = 4;   //
const int startswitch = 5;   //
int cntsteps = 0; //
 
void setup() {
 Serial.begin(9600);
  // Sets the two pins as Outputs
  pinMode(stepPin,OUTPUT); 
  pinMode(dirPin,OUTPUT);
  pinMode(cntsensor, INPUT);
  delay(5000);
}

void loop() {
  if (digitalRead(startswitch) == HIGH) {
      digitalWrite(dirPin,LOW); // Enables the motor to move in a particular direction
  // Makes 200 pulses for making one full cycle rotation
  for(int x = 0; x < 4000; x++) {
    digitalWrite(stepPin,HIGH); 
    delayMicroseconds(2000); 
    digitalWrite(stepPin,LOW); 
    delayMicroseconds(2000); 
  }
  }
if (digitalRead(cntsensor) == LOW) {
  cntsteps++;
  Serial.println(cntsteps);
  delay(1500);
}
}

Thanks

FedxE:
Hi, i'm working on a project where i have a stepper motor and i want to make 200 full revs(spins)(40,000 steps) and count each time it does a full revolution. The way i would like it to work is; when the stepper does 200 steps it increments the value for the variable "cntsteps".

There are probably several ways to do that.

One is to repeat a 200 step FOR loop 200 times and increment your counter at the end of each loop

Another is to increment a counter with every single step and when the step count gets to 200 increment the rev count and set the step count back to 0

...R