Go Down

Topic: Rewersing directionof stepper motor with limit switch (Read 2 times) previous topic - next topic

websonic

Hi everybody,
I am very new in this field,
can somebody help me with a sample code how to reverse direction of a stepper motor  when 5v is applied through limit switch?


I have managed to switch of an on LED, with switch, but Stepper are out of my range.

Thanks In advance

wildbill


websonic

#2
Feb 20, 2013, 05:20 pm Last Edit: Feb 20, 2013, 05:43 pm by websonic Reason: 1
It is 6  wire unipolar motor,
Controlled over arduino uno,

And i am trying to use accel stepper library

MarkT

[ I won't respond to messages, use the forum please ]

websonic

Hardly any,

I want to use random example from accelstepper

any ideas hot to incorporate two limit switches which would only reverse reverse direction if activated

Thanks in advance

// Random.pde
// -*- mode: C++ -*-
//
// Make a single stepper perform random changes in speed, position and acceleration
//
// Copyright (C) 2009 Mike McCauley
// $Id: Random.pde,v 1.1 2011/01/05 01:51:01 mikem Exp mikem $

#include <AccelStepper.h>

// Define a stepper and the pins it will use
AccelStepper stepper; // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5

void setup()

}

void loop()
{
    if (stepper.distanceToGo() == 0)
    {
   // Random change to speed, position and acceleration
   // Make sure we dont get 0 speed or accelerations
   delay(1000);
   stepper.moveTo(rand() % 200);
   stepper.setMaxSpeed((rand() % 200) + 1);
   stepper.setAcceleration((rand() % 200) + 1);
    }
    stepper.run();
}

Go Up