#include <Stepper.h>
#define STEPS 100
Stepper stepper(STEPS, 2, 3, 4, 5);
int previous = 0;
void setup() {
// set the speed of the motor to 30 RPMs
stepper.setSpeed(30);
curtains();
}
void loop() {
}
void curtains()
{
stepper.step(-500);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
delay(4000);
stepper.step(500);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
}
This is, I think, how you would normally address a stepper. I made this as prototype for my curtains, but currently I use it for cleaning my old vinyl records.
When you add Blynk it will look something like this:
#include <Stepper.h>
#define STEPS 100
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
// esp-two-relay local pi server
char auth[] = "<authkey here>";
Stepper stepper(STEPS, 2, 3, 4, 5);
int previous = 0;
void setup()
{
Serial.begin(9600);
Blynk.begin(auth, "Wanda2.4", "<wifipwd>", "<ip of server or leave blank for cloud>", 8442);
// set the speed of the motor to 30 RPMs
stepper.setSpeed(30);
curtains();
}
BLYNK_WRITE(v0)
{
// Execute curtains routine if V0 is pressed in dashboard
if(param.asInt)
{
curtains();
}
}
void loop()
{
Blynk.run();
}
void curtains()
{
stepper.step(-500);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
delay(4000);
stepper.step(500);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
}
This will execute the curtains void with a press of a button on V0. param.asInt() will catch the value of the virtual button, be it 0 or 1, and act accordingly 