Run loop on a button (steper motor) help

I have a issue whit code.
I want to run a loop on button.
When i press button steper motor should rotate 200 steps and stop .
End every time when I press button should to do that.
But it works only when i hold button.
I repleace pinout and issue is same.

Please help :slight_smile:

Here’s my code

program_start_loop122.ino (541 Bytes)

I did not download your code but from your description you should look at the state change detection example in the digital examples in the IDE File menu. That way you can know when the button BECOMES pressed not IS pressed.

I solved the problem

here code if need

int stp = 5; //connect pin 11 to step
int dir = 2; // connect pin 10 to dir
int buttonPin = 11;
int a = 0;

void setup()

pinMode(buttonPin, INPUT_PULLUP);

pinMode(stp, OUTPUT);
pinMode(dir, OUTPUT);

void loop()

if(digitalRead(buttonPin) == LOW) //functions based off of button pulling input pin LOW
digitalWrite(stp, HIGH);
digitalWrite(stp, LOW);



Why are you calling setup() in loop()? Very unusual.

And you might want to get in the habit of using autoformat from the tools menu (or ctrl t) to indent your code to make it easier to follow.