28byj-48 stepper motor with a push button


I am a beginner when it comes to arduino, and I want to control a 28byj- 48 stepper motor and uln2003 driver board with a push button. How would I do this. If possible I would like to be able to press the button once and the motor to rotate a certain number of times. But I am open to other forms of control. Please help, thanks.

Welcome to the forums. Start off by looking at the File->Examples->02.Digital->Button code to learn how to use a button and detect that it is either HIGH or LOW.

Then look at the State Change Example (File->Examples-02.Digital->State Change Detection) and learn how to detect when a button becomes pressed, not just if it is pressed. Use this detection to then control your motor. Look at the examples that came with your driver board library to learn how to control it.

Combine the two sketches.


I was doing testing with that very same setup. This worked for me.

#include  //include the function library  <<<< standard Arduino library
#define STEPS 64 // 64 steps per rev
Stepper stepper0(STEPS, 5, 3, 4, 2); //create the stepper0  <<< Order here is important

void setup()
  Serial.begin(9600); // initialize serial communication:
void loop()
  stepper0.setSpeed(120); //set speed to 10 rpm  <<< this go in setup()
  stepper0.step(640); //move 360 deg one direction
  delay(500); //pause for effect
  stepper0.step(-640); //move 360 deg in the other direction
  delay(500); //pause