stepper motor, inductive proximity sensor

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

void loop()

int analogValue = analogRead(analogPin);

if (analogValue < threshold)



What do you have in analogValue?

Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.,148850.0.html .
Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

What model Arduino are you using?
What are you driving the stepper motor with?
Link to specs/data please.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks… Tom… :slight_smile:

The inductive proximity sensors I have give a digital pulse output once when a steel gear tooth becomes present. What does your sensor do?


Why are you attempting to do a whole revolution upon detecting the threshold?

Surely you should step one step unless the threshold is reached, in which case you stop issuling steps?