good afternooon everyone, i have a trouble in my project, so basically, my 28byj-48 stepper motor just keeps rotating continuously and doesnt stop, what i want to do is that... when the inductive proximity sensor senses a metal, the stepper motor will rotate on a certain degree and back to its original position, and when the sensor is not sensing something, the motor will not do anything.... when i uploaded the code, the motor starts moving even if the sensor does not sense anything
here's the code
#include <Stepper.h>
double stepsPerRevolution = 600;
Stepper myStepper(stepsPerRevolution, 8, 10, 9, 11);
const int analogPin = A0;
const int threshold = 400;
void setup()
{
Serial.begin(9600);
myStepper.setSpeed(30);
pinMode(A0,INPUT);
}
void loop()
{
int analogValue = analogRead(analogPin);
if (analogValue < threshold)
{
myStepper.step(stepsPerRevolution);
delay(1);
myStepper.step(-stepsPerRevolution);
delay(1);
}
else
{
}
}