Uno with stepper control with push button

Hello guys and girls,

I`m completly new with arduino, and i have a question about my Arduino Uno R3 with an CNC controller

Is there a way to control a step driver with an Arduino Uno R3 thru 2 push buttons for direction?
So if i press the first button the stepper motor goes left and when i release the button it stops and when i push the second button the motor goes right and when i release this button it stops also

And is there a way to control the speed by a potenciometer

Any help would be great,
Thanxs

have you tried google arduino stepper button

Here is a demo that does what I think you want. This program uses the MobaTools stepper library. That library is available via the IDE library manager. How to install a library. This is written for an Uno with a CNC shield V3, DRV8825 (or A4988) stepper driver, 2 switches (wired to ground) and a pot. Change pins to suit your setup. Motor speed controlled by pot. Switches must be held down to keep a motor running.

#include <MobaTools.h>

const byte potPin = A0;
const byte ccSwPin = 9;
const byte ccwSwPin = 10;
const byte stepPin = 2;
const byte dirPin = 5;
const byte enablePin = 8;

const unsigned int motorStepsPerRev = 200;
const unsigned int microstepMultiplier = 4;
const int STEPS_REVOLUTION = motorStepsPerRev * microstepMultiplier;
const float adcCountsPerStep = 1023 / STEPS_REVOLUTION;

unsigned long interval = 50;
int speedMultiplyer = 2;

MoToStepper myStepper( STEPS_REVOLUTION, STEPDIR );

void setup()
{
   Serial.begin(115200);
   pinMode(ccSwPin, INPUT_PULLUP);
   pinMode(ccwSwPin, INPUT_PULLUP);
   myStepper.attach( stepPin, dirPin );
   myStepper.attachEnable(enablePin, 0, 1);   
   myStepper.setRampLen(100);
   myStepper.setZero();
}

void loop()
{
   static unsigned long timer = 0;   
   if (millis() - timer >= interval)
   {
      timer = millis();
      int speed = analogRead(potPin) * speedMultiplyer;
      myStepper.setSpeed(speed);
      //Serial.println(speed);
      if (digitalRead(ccSwPin) == LOW && digitalRead(ccwSwPin) == HIGH)
      {
         myStepper.rotate(1);
      }
      else if (digitalRead(ccSwPin) == HIGH && digitalRead(ccwSwPin) == LOW)
      {
         myStepper.rotate(-1);
      }
      else
      {
         myStepper.rotate(0);
      }
   }
}


1 Like

Thanxs for this i tried it and it works great
the only thing i changed is the ramp up and down time

Thanks VERY much for this

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.