Greeting everyone. I had a quick question. I am trying to get this
// Turn on the Sensor to begin finding my location then turn
// on the servo motor to determine position
// Then turn on stepper motors to begin having the car move
#include <Servo.h>;
#include <Stepper.h>;
const int PingPin = 12;
const int ledPin = 13;
Servo myservo; //create servo object to control a servo
//int angle = 0; //variable to store the servo position
const int stepsPerRevolution = 200; //change this to fit the number of steps per revolution
int cm;
Stepper myStepper(stepsPerRevolution, 3, 4, 5, 6);
Stepper myStepper2(stepsPerRevolution, 8, 9, 10, 11);
void setup()
{
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
myservo.attach(7);
myStepper.setSpeed(40);
}
void loop()
{
//Declare this as the main loop of the entire program
//Turn on the servo motor to determine location
//Servo myservo; //create servo object to control a servo
int angle = 0;
//myservo.attach(7);
//Serial.begin(9600);
Serial.println("SendA");
for (angle = 0; angle < 180; angle += 1);
{
myservo.write(angle);
delay(10);
}
for (angle = 180; angle >= 1; angle -= 1)
{
myservo.write(angle);
delay(10);
}
Serial.println("You have succeeded up to this point");
Serial.println("Now on to the Sensor");
int cm = ping(12);
Serial.println(cm);
digitalWrite(13, HIGH);
delay(cm * 10 ); //each centimeter adds 10 milliseconds delay
digitalWrite(ledPin, LOW);
delay( cm * 10);
//return cm;
// Activate stepper motors to move foward
// then begin looping if else statements
if (cm <= 50) {
Serial.println("counterclockwise");
myStepper.step(-stepsPerRevolution);
myStepper2.step(-stepsPerRevolution);
delay(100);
Serial.println("counterclockwise");
myStepper.step(-stepsPerRevolution);
myStepper2.step(-stepsPerRevolution);
delay (100);
}
else
{
Serial.println("clockwise");
myStepper.step(stepsPerRevolution);
myStepper2.step(stepsPerRevolution);
delay(100);
Serial.println("clockwise");
myStepper.step(stepsPerRevolution);
myStepper2.step(stepsPerRevolution);
delay(100);
}
}
int ping(int PingPin)
{
long duration, cm;
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
delayMicroseconds(2);
digitalWrite(ledPin, HIGH);
delayMicroseconds(5);
digitalWrite(ledPin, LOW);
pinMode(PingPin, INPUT);
duration = pulseIn(PingPin, HIGH);
//convert the time into a distance
cm = microsecondsToCentimeters(duration);
return cm;
}
long microsecondsToCentimeters(long microseconds)
{
return microseconds / 29 / 2;
}
to run using 2 Nema 17 stepper motors. Now the motors are connected to their respective pins on the Arduino and using a proper coloring code of Blue to the first pin recquired, Red to the second, Black to the 3rd pin, and Green to the fourth. I have the Arduino being powered by a battery pack of 5V. Now sometimes when I run the code, the first motor will either do its steps, or shudder, but the second motor will not do anything. I know the second motor will only start up once the first motor completes its designated number of steps, however my question comes when it shudders. If you feel the motor you can tell that it is recieving power, but after that it just continues to do nothing. What exactly is my problem?