I want to control the direction of stepper motor unipolar 6 wires via buttons in blynk interface … If button v1 clicks its starts rotating clockwise and if button v2 is clicked it starts rotating anticlockwise …
What I have used for this is
Wemos D1 mini
L298n h bridge
In1 to D5
In2 to D6
In3 to D7
In4 to D8
External power supply !
Wire Connections ok !
Program I have used…
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "cfd39c62ed714c73887231859768195d";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "NFY";
char pass[] = "qwertyuiop";
#include <Stepper.h>
const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution
Stepper myStepper( stepsPerRevolution, D5, D6, D7, D8 );
int previous = 0;
void setup()
{
// set the speed at 60 rpm:
myStepper.setSpeed(60);
Serial.begin(9600);
while (Blynk.connect() == false) {
// Wait until connected
}
}
BLYNK_WRITE(V1)
{
int b1 = param.asInt();
// Execute clockwise routine if V1 is pressed in dashboard
if (b1 == 0)
{
clockwise();
}
}
BLYNK_WRITE(V2)
{
int b2 = param.asInt();
// Execute counterclockwise routine if V2 is pressed in dashboard
if (b2 == 0)
{
counterclockwise();
}
}
void loop()
{
Blynk.run();
}
void clockwise()
{
// step one revolution in one direction:
Serial.println("clockwise");
myStepper.step(stepsPerRevolution);
delay(500);
}
void counterclockwise()
{
// step one revolution in the other direction:
Serial.println("counterclockwise");
myStepper.step(-stepsPerRevolution);
delay(500);
}
I think best spec is acceleration. Because stepper motor is syncronous motor. That mean, if you want to drive your motor on high speed, you need to accelerate your rotor.
First of all, you have to run your stepper without blynk.
@ManiYr07 I agree with this statement… Blynk itself doesn’t control steppers, relevant stepper code and libraries do.
Get it working and understand how it works with good old fashioned buttons or whatever the library examples use, then you can add in Blynk’s GUI interface to make it work from your phone.
But my past experience has been, due to steppers timing needs, I just used a normal UNO for the stepper code and sent commands to it from another ESP running Blynk… as demonstrated a bit here…
Follow this link. It is pretty clear. Lastly i offer accelstepper because running and stopping cycle controlled with acceleration to increase accuracy.
/* Simple Stepper Motor Control Exaple Code
*
* by Dejan Nedelkovski, www.HowToMechatronics.com
*
*/
// defines pins numbers
const int stepPin = 3;
const int dirPin = 4;
void setup() {
// Sets the two pins as Outputs
pinMode(stepPin,OUTPUT);
pinMode(dirPin,OUTPUT);
}
void loop() {
digitalWrite(dirPin,HIGH); // Enables the motor to move in a particular direction
// Makes 200 pulses for making one full cycle rotation
for(int x = 0; x < 200; x++) {
digitalWrite(stepPin,HIGH);
delayMicroseconds(500);
digitalWrite(stepPin,LOW);
delayMicroseconds(500);
}
delay(1000); // One second delay
digitalWrite(dirPin,LOW); //Changes the rotations direction
// Makes 400 pulses for making two full cycle rotation
for(int x = 0; x < 400; x++) {
digitalWrite(stepPin,HIGH);
delayMicroseconds(500);
digitalWrite(stepPin,LOW);
delayMicroseconds(500);
}
delay(1000);
}
I am using now A4988 stepper driver to control stepper motor
From this code I can successfully run stepper left right after delay using uno …
However I cant understand which pin ( Direction or step ) you have used in your code
pinMode(3, OUTPUT);
pinMode(1, INPUT_PULLUP);
this is the code you have attached …
What is 3 and 1 represent here…
Also tell me which stepper controller you have used …
If possible pls reply as quickly as possible
Awaiting for your kind response…