Hello sir,
I want to replace the stepper used in this project - https://create.arduino.cc/projecthub/lbf20012001/sound-location-finder-92e6b0?ref=search&ref_id=sound&offset=0
He used a SparkFun motor driver and a stepper motor..
I want to replace it with this one - Amazon.com
Is there something to change in the code so as to make the same project with this stepper?
If yes, Please help me!
Code -
const int stepsPerRevolution = 400; // change this to fit the number of steps per revolution for your motor
const int numberOfSteps = stepsPerRevolution/8; //45 degree turns
const int dirPin=12;
const int stepPin=13;
const int rightSensorPin=7;
const int leftSensorPin=8;
const int enablePin=5 ;
boolean rightVal = 0;
boolean leftVal = 0;
void setup()
{
pinMode(leftSensorPin, INPUT); //Make pin 8 an input pin.
pinMode(rightSensorPin, INPUT); //Make pin 7 an input pin.
pinMode (stepPin, OUTPUT); //Make pin 13 an output pin.
pinMode (dirPin, OUTPUT); //Make pin 12 an output pin.
pinMode (enablePin, OUTPUT); //Make pin 5 an output pin.
digitalWrite(enablePin, LOW); //Enable is active low
Serial.begin (9600); // initialize the serial port:
}
void loop ()
{
//poll inputs for signal
rightVal =digitalRead(rightSensorPin);
leftVal =digitalRead(leftSensorPin);
// when the sensor detects a signal above the threshold value set on sensor, turn finder to the direction of sound
if (leftVal==LOW && rightVal==HIGH)
{
Serial.println("Turning Right");
digitalWrite(dirPin,LOW); //turn counter-clockwise
//turn finder in the direction of the sound
for(int steps = 0; steps < numberOfSteps; steps++)
{
//create pulse to turn motor one step at a time
digitalWrite(stepPin,HIGH);
delayMicroseconds(10000);
digitalWrite(stepPin, LOW);
delayMicroseconds(10000);
}
delayMicroseconds(100000);
rightVal = 0;
leftVal = 0;
}
else if (leftVal==HIGH && rightVal==LOW)
{
Serial.println("Turning Left");
digitalWrite(dirPin,HIGH); //turn clockwise
//turn finder in the direction of the sound
for(int steps = 0; steps < numberOfSteps; steps++)
{
//create pulse to turn motor one step at a time
digitalWrite(stepPin,HIGH);
delayMicroseconds(10000);
digitalWrite(stepPin, LOW);
delayMicroseconds(10000);
}
delayMicroseconds(100000);
rightVal = 0;
leftVal = 0;
}
else
{
//Do nothing
rightVal = 0;
leftVal = 0;
}
}
Thank You