So, 1 pulley rotation moves the belt 60mm, 1500 / 60 = 25. 25 * 400 = 10000. So, 10000 steps to move the belt 1500mm. Does that sound right?.
Yes, you are correct.
As per this programme the motor is not moving 1500mm. What changes I need to do in this program to move it 1500mm in one direction and than stop.
const byte PinPot = A0;
const byte PinBut = 2;
const byte PinLmt = 3;
const byte PinDir = 8;
const byte PinStep = 9;
// -----------------------------------------------------------------------------
const unsigned long StepDelayMax = 50000;
const unsigned long StepDelayMin = 1000;
unsigned long stepDelayUsec = StepDelayMax;
unsigned long stepDelayUsecLst = stepDelayUsec;
const unsigned long PosMax = 1000;
const unsigned long PosMin = 0;
long motorPos;
enum { Forward = LOW, Reverse = HIGH };
long motorDir;
// -----------------------------------------------------------------------------
// move motor when button pressed, update step delay using pot
void loop ()
{
if (LOW == digitalRead (PinBut)) {
if (0 == motorPos)
step (PosMax);
else
step (-PosMax);
}
stepDelayUsec = map(analogRead(PinPot), 0, 1023, StepDelayMin, StepDelayMax);
if (abs(stepDelayUsecLst - stepDelayUsec) > 200) {
stepDelayUsecLst = stepDelayUsec;
Serial.print ("stepDelayUsec = ");
Serial.println (stepDelayUsec);
}
}
// -----------------------------------------------------------------------------
// step motor specified # of steps in direction specified by sign
void step (
long nStep)
{
Serial.print ("step: ");
Serial.print (nStep);
if (0 < nStep) {
Serial.println (" forward");
digitalWrite (PinDir, Forward);
}
else {
Serial.println (" reverse");
digitalWrite (PinDir, Reverse);
}
motorPos += nStep;
nStep = abs(nStep);
while (nStep--) {
digitalWrite (PinStep, HIGH);
delayMicroseconds (stepDelayUsec);
digitalWrite (PinStep, LOW);
delayMicroseconds (stepDelayUsec);
}
Serial.print (" step complete, motorPos = ");
Serial.println (motorPos);
}
// -----------------------------------------------------------------------------
// drive motor toward limit switch and stop when switch active
void
home ()
{
Serial.println ("home ...");
digitalWrite (PinDir, Reverse);
while (HIGH == digitalRead (PinLmt))
step (-1);
motorPos = PosMin;
Serial.println (" ... home complete");
}
// -----------------------------------------------------------------------------
void setup ()
{
Serial.begin (115200);
Serial.println ("Starting Stepper Demo with micros ()");
pinMode (PinDir, OUTPUT);
pinMode (PinStep, OUTPUT);
pinMode (PinBut, INPUT_PULLUP);
pinMode (PinLmt, INPUT_PULLUP);
home ();
}
Maybe this?
// This code moves the motor 1500mm in one direction and then stops.
// Adjust the PosMax value to match your specific hardware configuration
Remember, we said 1500mm was 10000 steps.
Understood, so I will change the PoxMax to 10000 so that I get the distance travel equal to 1500mm along one direction.
const unsigned long PosMax = 10000;
Thanks johnsmith, I will make the adjustments and let you all know how the hardware runs.
this block of code is intended to be active when a button connected between the pin and Ground is pressed and pulls the pin LOW.
if the button wired that way?
what does home do? or is that switch also wired to ground the pin by default?
The motor is running exactly 25 turns and stopping.
The number of turns are as required but the speed is less. I need to double the speed of motor. How can I do that?
Thanks for your inputs
Hi Gcjr, I really appreciate that you are helping me a lot.
My motor home position is A. When I press switch the motor moves to position B (1500mm away) or hits the limits switch and reverses back to position A. Can you make it work this way?
Thanks
does it home? and stop?