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
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