#include <Stepper.h>
const int stepsPerRevolution = 200; // Number of steps per revolution for your motor
//const int stepSegment = 20; // Segment size (20 steps per segment)
Stepper myStepper(stepsPerRevolution, 10, 11, 12, 13);
#define LimitBtn 9
unsigned long debounceDuration = 50; // millis
void setup() {
pinMode(LimitBtn, INPUT_PULLUP);
myStepper.setSpeed(10); // Set motor speed to 10 RPM
Serial.begin(9600);
// Find. home position at startup
Serial.println("Finding home position...");
while (digitalRead(LimitBtn) == HIGH) {
// Move until the limit switch is touched (LOW)
myStepper.step(-1); // Move step by step in a direction to find home
delay(10); // Small delay between steps
}
// Stop motor once home position is found
Serial.println("Home position found!");
myStepper.step(0); // Stop the motor
}
void loop() {
// Additional logic can be implemented here
}