Stepper motor 1 step by pressing pushbutton once

I am using TB6600 and power supply with nema 17, How can I achieve one step for nema which is coupled to a lead screw and its job is to up the table 1 micron.

What have you tried ?

Do you know how to advance the stepper by 1 step ?

1 Like

nope

If I remember correctly there is a Stepper library installed with the IDE and there are examples with it

Most libraries have examples, that's where to start. There'll also be an example of debouncing a push button in the main example sketches IIRC.

Combine the simple stepper code to step the motor one step with the state change detection example code., but use the active low switch as in the state change for the 21st century tutorial,

This will advance the stepper one step per button (switch) press:

/*
   The circuit:
   - pushbutton attached to pin 10 from ground
   - the internal pullup on pin 10 is enabled
   - LED attached from pin 13 to ground (or use the built-in LED on most
    Arduino boards)
*/

// this constant won't change:
const byte stepPin = 2;
const byte dirPin = 5;
const byte enablePin = 8;
const byte  buttonPin = 10;    // the pin that the pushbutton is attached to
const byte ledPin = 13;       // the pin that the LED is attached to

// Variables will change:
int buttonPushCounter = 0;   // counter for the number of button presses
boolean buttonState = 0;         // current state of the button
boolean lastButtonState = 0;     // previous state of the button

void setup()
{
   pinMode(buttonPin, INPUT_PULLUP);
   pinMode(ledPin, OUTPUT);
   pinMode(stepPin, OUTPUT);
   pinMode(dirPin, OUTPUT);
   pinMode(enablePin, OUTPUT);
   digitalWrite(enablePin, LOW); // enable steppers
   // initialize serial communication:
   Serial.begin(9600);
}


void loop()
{

   static unsigned long timer = 0;
   unsigned long interval = 20;
   if (millis() - timer >= interval)
   {
      timer = millis();
      buttonState = digitalRead(buttonPin);
      if (buttonState != lastButtonState)
      {
         if (buttonState == LOW)
         {
            singleStep();
         }
         // save the current state as the last state, for next time through the loop
         lastButtonState = buttonState;
      }
   }
}
void singleStep()
{     
      digitalWrite(stepPin, HIGH);
      digitalWrite(stepPin, LOW);   
}