Stepper Motor Project Help

Hi Everyone!

I am trying to do something simple but I am new to this and can’t quite figure out how it works!

What I want to do is rotate a bi-polar stepper motor with the press of a button. I have started a sketch and designed a circuit setup but when I put it together it did not work. I am using a SN754410 as a driver and the motor I am using needs 15V and 100 mA.

Any suggestions would be greatly appreciated!
Thanks!

Sketch:
#include <Stepper.h>
// constants won’t change. They are used here to set pin numbers:
const int buttonPin = 2; //the number of the pushbutton pin
const int in1Pin = 8; //these four lines are the pin number for
const int in2Pin = 9; //stepper motor control
const int in3Pin = 10;
const int in4Pin = 11;

Stepper myStepper(2045.45, in1Pin,in2Pin,in3Pin,in4Pin); //represents stepper:

int buttonState = 0; //variable for reading the pushbutton status

void setup()
{

pinMode (buttonPin, INPUT); //initialize the pushbutton pin as an
// input:
pinMode (in1Pin, OUTPUT); //initialize in#Pin as an output
pinMode (in2Pin, OUTPUT);
pinMode (in3Pin, OUTPUT);
pinMode (in4Pin, OUTPUT);

myStepper.setSpeed(.5); //set the motor speed at .5 RPM
}

void loop()
{
//read the state of the bushutton value:
buttonState = digitalRead(buttonPin);

//check if the pushbutton is pressed.
//if it is, the buttonState is HIGH:
if (buttonState == HIGH){
//turn motor 28 steps (about 5 degrees for this motor):
myStepper.step(28.4);
}

else {
// don’t move motor
myStepper.step(0);

}
}

and designed a circuit setup but when I put it together it did not work.

And you won't show us what it is so we can't tell you what is wrong.

Read the how to use the forum sticky post about posting code correctly as well and maybe we can get somewhere to helping you.

Sorry about that.

#include <Stepper.h>
// constants won’t change. They are used here to set pin numbers:
const int buttonPin = 2; //the number of the pushbutton pin
const int in1Pin = 8; //these four lines are the pin number for  
const int in2Pin = 9; //stepper motor control 
const int in3Pin = 10;
const int in4Pin = 11;

Stepper myStepper(2045.45, in1Pin,in2Pin,in3Pin,in4Pin); //represents stepper:

int buttonState = 0; //variable for reading the pushbutton status

void setup() 
{

pinMode (buttonPin, INPUT);  //initialize the pushbutton pin as an  
                // input:
pinMode (in1Pin, OUTPUT);  //initialize in#Pin as an output
pinMode (in2Pin, OUTPUT);
pinMode (in3Pin, OUTPUT);
pinMode (in4Pin, OUTPUT); 

myStepper.setSpeed(.5); //set the motor speed at .5 RPM
}


void loop() 
{
//read the state of the bushutton value:
buttonState = digitalRead(buttonPin);

//check if the pushbutton is pressed.
//if it is, the buttonState is HIGH:
if (buttonState == HIGH){
//turn motor 28 steps (about 5 degrees for this motor):
myStepper.step(28.4);
}

else { 
// don’t move motor
myStepper.step(0);

   }
}

It helps to have a schematic Thayer than a physical layout diagram, those are useless except for the most trivial circuits.

The key to fault finding is to break it down into steps.
Write a simple sketch that just moves the motor nothing else. Does that work? If not have steps go very slowly about 5 seconds a step and check with a multi meter the coils are being energised in the correct order.

While it will not stop it working it is best to have sensible names for things. Something called inPin which is an output is not very sensible.

@Grumpy_Mike - that is good advice.

However is "Thayer" on line 1 a typo? Because it is capitalized it may be confusing. I suspect you meant "rather", but it took me a while to figure out.

...R