Hello, I work at a rehab center and am working to set up a system that releases a little token into a plinko board. Currently I am using a stepper motor to move a contraption back and forth and then 2 mini servos motors that open and release the token. Upon pushing a button, the stepper moves a random number of steps and then the 2 servos open 90 degrees. I am trying to figure out how to either set up limit switches or one homing switch for the stepper motor. I am using a 5V 28BYJ-48 with a ULN2003 and Arduino uno. I attached my code, in the set up I added a second button because I have been playing around with different things.
#include <Servo.h>
#include <Stepper.h> // include stepper library
int revolution = 2038; // the number of steps in one revolution of your motor (28BYJ-48)
Stepper stepper(revolution, 8, 10, 9, 11);
int buttonPin=3;
int buttonPin1=5;
Servo servo1;
Servo servo2;
int buttonState = 0;
int buttonState1 = 0;
void setup() {
Serial.begin(9600);
servo1.attach(4);
servo2.attach(7);
pinMode(8, OUTPUT);
pinMode(10, OUTPUT);
pinMode(9, OUTPUT);
pinMode(11, OUTPUT);
servo1.write(0);
servo2.write(180);
delay(2000);
pinMode(buttonPin, INPUT_PULLUP);
pinMode(buttonPin1,INPUT_PULLUP);
}
void loop() {
delay(100);
buttonState = digitalRead(buttonPin);
buttonState1 = digitalRead(buttonPin1);
uint8_t i;
if((buttonState==LOW)){
stepper.setSpeed(10);
stepper.step(random(-5000, 5000));
delay(1000);
Serial.println("i entered");
servo1.write(90);
servo2.write(90);
delay(1000);
servo1.write(0);
servo2.write(180);
delay(1000);
}
else{
}
}