I am trying to make my code run so that when the phoneValue is positive, the stepper motor turns but as it is when the code is run the motor makes a sound as though it is turning but no movement is seen. When i comment out the Blynk code and just run the motorOn() function it runs smoothly and the motor turns…
//Blynk set up code
#include <Blynk.h>
#include <SPI.h>
#include <BlynkSimpleEthernet.h>
#include <Ethernet.h>
#define BLYNK_PRINT Serial
#define W5100_CS 10
char auth[] = "xxx";
//motor set up code
#include <Stepper.h>
const int stepsPerRevolution = 200;
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);
void setup() {
Blynk.begin(auth);
myStepper.setSpeed(60);
Serial.begin(9600);
}
BLYNK_WRITE(V1) {
int phoneValue = param.asInt();
Serial.println(phoneValue);
if (phoneValue){
Serial.println("motor on");
motorOn();
}
}
void motorOn() {
int ClockwiseRev = 0;
while (ClockwiseRev < 3) {
Serial.print("turning clockwise. this is revolution number (of 3 from 0): ");
Serial.println(ClockwiseRev);
myStepper.step(5 * stepsPerRevolution);
delay(500);
ClockwiseRev = ClockwiseRev + 1;
}
int antiClockwiseRev = 0;
while (antiClockwiseRev < 3) {
Serial.print("turning anti-clockwise. This is revolution number (of 3 from 0): ");
Serial.println(antiClockwiseRev);
myStepper.step(5*-stepsPerRevolution);
delay(500);
antiClockwiseRev = antiClockwiseRev + 1;
}
}
void loop() {
Blynk.run();
}