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?