Button Press Stepper Motor.

Total Newbee, 1st ever post, 1st ever project!!

I have a 28BYJ-48 stepper motor and a UNO,

My objective is to simply make the stepper motor turn a set amount of steps in a single direction after a single button press from a momentary switch. I am trying to make a measuring device that will spool out an appropriate length by pinching between a set of rollers (the stepper and an idler). I can then expand the code and add more buttons so i can spool different lengths depending on which button is pressed.

I have downloaded a sample sketch code for the 28BYJ-48 and I have wired it to work, so I get a full revolution in one direction followed by a full revolution in the other.... I guess I can butcher this code and add the code for the button press?

can anyone point me in the right direction for the programming needed to do this?


You can use digitalread to read the state of your button. To avoid issues with switch bounce you need to detect a transition from LOW to HIGH or vice versa depending on your button wiring. You'll need pullup or pulldown resistors - pullup is easier becase the Amtel chip provides them. When you detect button transition, run the code that moves the stepper. Search the forum separately for debounce, prevbuttonstate, pullup, transition. You should find a plethora of posts and code that will help.

Edit: replaced digitalwrite with digitalread - D'oh!

many thanks for the pointers...