Go Down

Topic: stepper motor, inductive proximity sensor (Read 201 times) previous topic - next topic

TheWarrior123

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

wildbill


TomGeorge

#2
Sep 03, 2019, 02:35 pm Last Edit: Sep 03, 2019, 02:35 pm by TomGeorge
Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,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.... :)
Everything runs on smoke, let the smoke out, it stops running....

Paul_KD7HB

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

Paul

MarkT

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?
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

Go Up