Control Nem 17 ,A4988 via bluetooth

Hi everyone ,i want to control nema17 via bluetooth hc-05 with A4988 , but i cannot control motor via bluetooth , please help me

Sketch_bb.pdf (611.2 KB)

const int dirPin = 2;
const int stepPin1 = 3;
const int stepall = 20000;

void setup()
{
  // Declare pins as Outputs
  Serial.begin(9600);
  pinMode(stepPin, OUTPUT);
  pinMode(dirPin, OUTPUT);
}
void loop()
{
  if (Serial.available()>0)
  {
    String D = Serial.readString();
    if (D == "left")
    {
      digitalWrite(dirPin, LOW);
      for (int i = 0; i < stepall; i++) {
        digitalWrite(stepPin , HIGH);
        delayMicroseconds(5000);
        digitalWrite(stepPin , LOW);
        delayMicroseconds(5000);
      }
    } else if (D == "right")
    {
      digitalWrite(dirPin, HIGH);
      for (int i = 0; i < stepall; i++){
        digitalWrite(stepPin , HIGH);
        delayMicroseconds(5000);
        digitalWrite(stepPin1, LOW);
        delayMicroseconds(5000);
      }
    } 
  }
}
```!

Using a PP3 battery to power a stepper is not good. I would never try that. The same applies to controller - BT. The controller 5 volt converter will likely not manage.
Make a sketch that only run BT. Do the same for the stepper. When that also works build the final code.

1 Like