Stepper motor driver changing

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

You are switching to a different type of driver. The old one is a step/dir type driver for bipolar motors that uses 2 pins. The new one is a 4 pin driver for unipolar motors that needs a sequence of states to rotate the motor. The software to control those driver types is very different.

The old motor is 400 steps per revolution (uses 2x microstepping) and the new motor is of the 28BYJ type with, usually, 2038 steps per revolution or if using HALFSTEP, 4076 steps per revolution.

The old motor driver required at least 8V motor supply voltage. The new motor is rated at 5V.

So you will need to make a lot of changes to the stepper hardware and software. I would start with checking out the MobaTools stepper library. That library makes it pretty easy to control the 4 wire unipolar motor.
There are 2 types of motion in the MobaTools library. The moveTo() function will go to an absolute position. The move() function will go to a relative position. The documentation in the MobaTools-243-en.pdf file explains all of the functions.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.