Programming a Stepper motor, DC Motor, and optical sensor

I am a college student, currently struggling to write a code that will allow my device to have a bipolar stepper motor move 90 degrees, stop, and then once stopped, have a DC motor run until an optical sensor is activated. Once the optical sensor is no long active, the Stepper motor should move another 90 degrees and the same process should continue 12 times. I really need help. If anyone can look at what I have so far and help me in any way possible that would be amazing.

//necessary to run stepper motor
#include <Stepper.h>
//these are the the pins where the stepper motor will be located
int in1Pin = 12;
int in2Pin = 11;
int in3Pin = 10;
int in4Pin = 9;

//how many steps for a full revolution for stepper motor
Stepper motor(200, in1Pin, in2Pin, in3Pin, in4Pin);

void setup() {
pinMode(3,INPUT_PULLUP); //sensor
pinMode(8,OUTPUT); //DC motor

pinMode(in1Pin, OUTPUT);
pinMode(in2Pin, OUTPUT);
pinMode(in3Pin, OUTPUT);
pinMode(in4Pin, OUTPUT);

Serial.begin(9600);
//push the button on the device to start (I NEED TO DO THIS)
motor.setSpeed(Change as fit);//don't know if this is right
}

void loop() {

//make for loop here that tells stepper motor to rotate 90 degrees when code below is complete (I NEED TO DO THIS)
// While the sensor is not detecting a card, it will run the motor.
while(pinMode(3)==LOW){
pinMode(8,HIGH);
}
pinMode(8,LOW); //stops motor after sensor is no longer low.

}

// how will we have this process repeat 12 times?

Please modiy your Post and use the code button </>

so your code looks like this

and is easy to copy to a text editor.

You need to deal with the problem in small pieces.

  • Have you been able to get your stepper motor and your DC motor to work in two separate and simple programs. If not, you should do that first.
  • Can you make the stepper motor turn through 90 deg?
  • Can you get the optical detector to work - perhaps just to print a message on the Serial Monitor when it is triggered.
  • Can you make the DC motor run until the optical detector is triggered?

When you can do the parts separately it will be time to start combining them.

The Tutorial Planning and Implementing a Program shows how a large project is just a collection of small functions. Each of the function can be developed and tested on its own.

It would be a good idea to post links to the datasheets for your stepper motor and for your stepper driver.

...R
Stepper Motor Basics
Simple Stepper Code