welcome to the forums. Please read the sticky post at the top of the forum about how to post your code. If you put it in the message using code tags, it makes it easier for people to help you. like this:
/*
Stepper Motor Demonstration 4
Stepper-Demo4.ino
Demonstrates NEMA 17 Bipolar Stepper with A4988 Driver
DroneBot Workshop 2018
https://dronebotworkshop.com
*/
// Define Constants
// Connections to A4988
const int dirPin = 2; // Direction
const int stepPin = 3; // Step
const int dirPin_2 = 4;
const int stepPin_2 = 5;
const int solenoidPin = 7;
const int Detector = 8;
// Motor steps per rotation
const int STEPS_PER_REV = 200;
void setup() {
// Setup the pins as Outputs
pinMode(stepPin, OUTPUT);
pinMode(stepPin_2, OUTPUT);
pinMode(dirPin, OUTPUT);
pinMode(dirPin_2, OUTPUT);
pinMode(solenoidPin, OUTPUT); //Sets that pin as an output
pinMode(Detector, INPUT);
}
void loop() {
if (digitalRead(Detector) == LOW) {
//solenoid control
digitalWrite(solenoidPin, HIGH); //Switch Solenoid ON
delay(1000); //Wait 1 Second
digitalWrite(solenoidPin, LOW); //Switch Solenoid OFF
delay(100); //Wait 1 Second
// Set motor direction clockwise
digitalWrite(dirPin, HIGH);
// Spin motor_1 one rotation slowly
for (int x = 0; x < STEPS_PER_REV; x++) { //controls number of rotations
digitalWrite(stepPin, HIGH); //I believe this is the control of the unique coils, it goes between high and low to drive the motor with a puny microsecond delay.
delayMicroseconds(500); //controls amount of time revolution takes
digitalWrite(stepPin, LOW);
delayMicroseconds(500);
}
}
delay(200);
if (digitalRead(Detector) == LOW) {
//solenoid control
digitalWrite(solenoidPin, HIGH); //Switch Solenoid ON
delay(1000); //Wait 1 Second
digitalWrite(solenoidPin, LOW); //Switch Solenoid OFF
delay(100); //Wait 1 Second
// Set motor direction clockwise
digitalWrite(dirPin, HIGH);
// Spin motor_1 one rotation slowly
for (int x = 0; x < STEPS_PER_REV; x++) { //controls number of rotations
digitalWrite(stepPin, HIGH); //I believe this is the control of the unique coils, it goes between high and low to drive the motor with a puny microsecond delay.
delayMicroseconds(500); //controls amount of time revolution takes
digitalWrite(stepPin, LOW);
delayMicroseconds(500);
}
}
delay(200);
if (digitalRead(Detector) == LOW) {
//solenoid control
digitalWrite(solenoidPin, HIGH); //Switch Solenoid ON
delay(1000); //Wait 1 Second
digitalWrite(solenoidPin, LOW); //Switch Solenoid OFF
delay(100); //Wait 1 Second
// Set motor direction clockwise
digitalWrite(dirPin, HIGH);
// Spin motor_1 one rotation slowly
for (int x = 0; x < STEPS_PER_REV; x++) { //controls number of rotations
digitalWrite(stepPin, HIGH); //I believe this is the control of the unique coils, it goes between high and low to drive the motor with a puny microsecond delay.
delayMicroseconds(500); //controls amount of time revolution takes
digitalWrite(stepPin, LOW);
delayMicroseconds(500);
}
}
delay(200);
if (digitalRead(Detector) == LOW) {
//solenoid control
digitalWrite(solenoidPin, HIGH); //Switch Solenoid ON
delay(1000); //Wait 1 Second
digitalWrite(solenoidPin, LOW); //Switch Solenoid OFF
delay(100); //Wait 1 Second
// Set motor direction clockwise
digitalWrite(dirPin_2, HIGH);
// Spin motor_1 one rotation slowly
for (int x = 0; x < STEPS_PER_REV; x++) { //controls number of rotations
digitalWrite(stepPin_2, HIGH); //I believe this is the control of the unique coils, it goes between high and low to drive the motor with a puny microsecond delay.
delayMicroseconds(500); //controls amount of time revolution takes
digitalWrite(stepPin_2, LOW);
delayMicroseconds(500);
}
// Set motor direction counter-clockwise
digitalWrite(dirPin, LOW);
// Spin motor_1 one rotation slowly
for (int x = 0; x < (600); x++) { //controls number of rotations
digitalWrite(stepPin, HIGH); //I believe this is the control of the unique coils, it goes between high and low to drive the motor with a puny microsecond delay.
delayMicroseconds(500); //controls amount of time revolution takes
digitalWrite(stepPin, LOW);
delayMicroseconds(500);
}
}
}
A couple of things stand out. How is your detector wired up? You have it defined as an input but it may need to be an INPUT_PULLUP so that it is not floating.
I hope you are not trying to drive a solenoid directly with an arduino pin. They can ony deliver 40mA and a solenoid will take way more than that.
A schematic, even hand drawn, would be useful.