BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Blynk, AccelStepper, Stepper Motor

android

#1

Im having issues with my code, I’m trying to get my stepper motor to turn forwards and backwards (Left/Right) Depending on the V1 & V2 buttons being pushed. However the code doesn’t seem to be activating

Here is my code

 #include <Stepper.h>;

 #include <AccelStepper.h>
#include <SPI.h>
#include <SoftwareSerial.h>
#include <BlynkSimpleStream.h>

SoftwareSerial SwSerial(10, 11); // RX, TX
char auth[] = "62b6ba779d0e47d3850d031059bea256";



#define ENABLE       8

AccelStepper stepper1(2, 5); // pin 3 = step, pin 6 = direction

void setup() {

  pinMode(ENABLE, OUTPUT);
  SwSerial.begin(9600);
  Serial.begin(9600);
  delay(10);
  Blynk.begin(Serial, auth);
  delay(10);
  while (Blynk.connect() == false) {
  }
 
}



BLYNK_WRITE(V2) // Button Widget writes to Virtual Pin V5 
{
  int rightBtn = param.asInt();
  if(rightBtn == 1) {     // if Button sends 1
right();             // start the function
  }
}
void right(){
digitalWrite(ENABLE, LOW);
stepper1.setMaxSpeed(2000.0);
stepper1.setAcceleration(500.0);
stepper1.moveTo(1000);
 
}

BLYNK_WRITE(V1) // Button Widget writes to Virtual Pin V5 
{
  int leftBtn = param.asInt();
  if(leftBtn == 1) {     // if Button sends 1
left();             // start the function
  }
}
void left(){
digitalWrite(ENABLE, LOW);
stepper1.setMaxSpeed(2000.0);
stepper1.setAcceleration(500.0);
stepper1.moveTo(-1000);
 
}






void loop() {  

 stepper1.run();

}

#2

Hmmm… I wonder why?

For Blynk to work, it needs Blynk.run(); in the void loop, and it doesn’t tend to like other stuff in there as well.

Try searching the forum for Stepper Motor and you’ll find a gazillion working examples.

Pete.


#3

@Casper_Round As recommended in the Welcome Topic that everyone reads first :wink: … Searching and reading is a good thing :stuck_out_tongue_winking_eye:

HINT somewhere in here might be what you are looking for… at least to get you on the right track.