Stepper motor and esp-01

I want to use an esp-01 and a mega arduino to control a stepper motor (28byj-48 + ULN2003) that at blynk will activate when I press a button on the mobile app, or it will activate when the time is determined (using an RTC ds3231 as a reference) that I I also have to put it in the code through the app, and I want that through a module hx711 + load cell, the scale is indicated in the app Having said that and taking into account that I don’t understand programming well, my question more specifically in this topic is: how to put the activate part by the button? (but I accept help with the rest of the project too)
my code by now is



#include <Stepper.h>

#define e1 8
#define e2 8
#define e3 9
#define e4 11
 const int passosPorGiro=64;

 Stepper mp(passosPorGiro,e1,e2,e3,e4);

 void setup(){
  mp.setSpeed(500);//RPM
}  
void loop() {
 for(int i=0;i<64;i++){
  mp.step(passosPorGiro);
 }
 delay(300);
} 

That’s going to be a problem, as working within stepper motors in Blynk isn’t easy. Steppers are very fussy about timing, and so is Blynk.

Your void loop is currently incompatible with Blynk, for a number of reasons, but mainly because of the blocking delay.
You should read this:
http://help.blynk.cc/en/articles/2091699-keep-your-void-loop-clean

I’d suggest that you search the forum for other examples of working projects which use stepper motors and start by experimenting with and modifying those. You can then go on to adding in the HX711 code.

You’re probably on your own with this, as its very unlikely that other forum members will have the same hardware kicking around to test code with, so any advice you get will require you to run with it and turn it into a finished solution - which requires a reasonable level of coding ability.

Pete.

2 Likes

@PeteKnight

ok, sorry for the delay, I decided to study a little about everything that was mentioned and I came to the following problem

/ Include the AccelStepper Library
#include <AccelStepper.h>

// Creates an instance
// Pins entered in sequence IN1-IN3-IN2-IN4 for proper step sequence
AccelStepper myStepper(AccelStepper::FULL4WIRE, 4, 6, 5, 7);
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial


#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
int pinValue;
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "xxxxxxxxxxxx";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "xxxxxx";
char pass[] = "xxxxxx";

// Hardware Serial on Mega, Leonardo, Micro...
#define EspSerial Serial1

// or Software Serial on Uno, Nano...
//#include <SoftwareSerial.h>
//SoftwareSerial EspSerial(2, 3); // RX, TX

// Your ESP8266 baud rate:
#define ESP8266_BAUD 9600

ESP8266 wifi(&EspSerial);

void setup()
{
  Serial.begin(9600);
  BLYNK_WRITE(V0) {
    pinValue = param.asInt(); // assigning incoming value from pin V0 to a variable
    pinMode(V0, OUTPUT);
  }
  // set the maximum speed, acceleration factor,
  // initial speed and the target position
  myStepper.setMaxSpeed(1000.0);
  myStepper.setAcceleration(100.0);
  myStepper.setSpeed(900.0);
  myStepper.moveTo(pinValue * 2038ul);
  // aqui serve para setar o numero de voltas que o motor
  // vai dar, então no caso é melhor que marcar o tempo
  // em minutos 1 volta=2038
  // Set ESP8266 baud rate
  EspSerial.begin(ESP8266_BAUD);
  delay(10);

  Blynk.begin(auth, wifi, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, wifi, ssid, pass, "blynk-cloud.com", 80);
  //Blynk.begin(auth, wifi, ssid, pass, IPAddress(192,168,1,100), 8080);
}

I have this code, in short it can connect the esp to the internet and any value that I throw there to multiply with the 2038, it means the number of turns that the engine will take, but my doubt is the following, as I should to add the value of a slider to be multiplied by 2038? I wanted the value that came out to be what determined the number of turns and although I understood how it works for me to say what pin the slider is on, I was not able to make this part work
including forgiveness but the instruction said it was to use the back to paste the codes when in fact it was to use the serious accent

I think that’s it, I hope it’s okay to take so long to post and thank you for your attention now

I think you need to learn more about C++ programming before you get into a project like this.
If you’re the type of person that likes to learn by watching videos then find a basic Arduino/C++ programming series on YouTube that’s in your native language.

Pete.