Blynk stepper motor

how can i put switch in this code

First of all, you should read this
https://docs.blynk.io/en/legacy-platform/legacy-articles/keep-your-void-loop-clean

I want it to stop automatically when the stepper motor is running with the help of blynk and swich.

@Yusuf_Gdk Please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:
```

Copy and paste these if you can’t find the correct symbol on your keyboard.

Pete.

this is the code. I request you to add switch code to stepper motor

please explain what are you trying to achieve exactly.

How can I add a switch button to the system in this video?

Before we can give you any guidance about hoe to do that, we need to understand exactly what it is that you are hoping to achieve.

This project already has two switch widgets, what is it that your addition switch is meant to do?

Also, the code in this project is incredibly badly written, and if you’ve read the “keep your void loop clean” link that @John93 provided then you’ll realise this.

Members of this user community are happy to help other users, but it’s difficult to help if you don’t explain what it is that you are trying to achieve, or don’t take the time to read the links that we provide.
Also, it seems that you’d rather search YouTube for information than this forum, which isn’t the best approach in my opinion.

Pete.

In this way, when the switch is connected and the stepper motor comes to the end of the drawer, it should stop by the automatic switch. Could you help

Okay, a limit switch.

Connect one side of the switch to GND and the other to one of your GPIO pins.
In void setup add a pinMode statement that declares the pin as an INPUT_PULLUP.

You then have two choices:

  1. attach an interrupt that pin, and when that interrupt is triggered it calls a function which will stop the stepper motor.

  2. poll the pin using a timer, checking if the pin has changed from HIGH to LOW, indicating that the switch has changed state. If it has then call a function which will stop the stepper motor.

The details of what your function to stop the stepper motor will look like depends a lot on how you restructure the original sketch to sort-out the void loop.

Pete.

I do not have the knowledge to do this procedure, can you do it for me, please?

I’m not going to write your code for you, but you may be lucky and find another forum member who will.

I prefer to coach people to write their own code, and learn a new skill in the process.

Pete.

So, your project is a drawing machine. Personally, I don’t think Blynk is suitable for such a project.

I realized that blynk can’t make it

You can use blynk to control a stepper motor, but it’s not suitable for drawing machine or CNC projects.
I’d suggest using GRBL firmware instead.

thanks

hello, I want to add a limit switch to stop the code I wrote, but I couldn’t succeed, can you help me?


#include <ESP8266WiFi.h>

#include <BlynkSimpleEsp8266.h>

#include <Stepper.h> // Include the header file

#define BLYNK_PRINT Serial

// change this to the number of steps on your motor

#define STEPS 64

// create an instance of the stepper class using the steps and pins

Stepper stepper(STEPS, D0, D7, D6, D5);

// You should get Auth Token in the Blynk App.

// Go to the Project Settings (nut icon).

char auth[] = "BXJHLmqGmwlUF8WZuTHBrdhpGYpvZAdG";

// Your WiFi credentials.

// Set password to "" for open networks.

char ssid[] = "AirTies_Air5650_7GD7";

char pass[] = "123onr456";

//Run the program only after opening the blinds

boolean closed = false;

boolean opened = true; 

void disable_motor() //turn off the motor when done to avoid heating

{

  digitalWrite(D1,LOW);

  digitalWrite(D2,LOW);

  digitalWrite(D3,LOW);

  digitalWrite(D4,LOW);

}

void setup()

{

  pinMode(D0, OUTPUT); //on-board LED as output 

  digitalWrite(D0,HIGH); //turn this light on 

  Serial.begin(9600);

  stepper.setSpeed(500);

  Blynk.begin(auth, ssid, pass);

  //http://188.166.206.43/l_b47mF1hioCc_7FzdKMJJeFnJjxxxx_/update/V1?value=1 /

  digitalWrite(D0,LOW); //turn it off after connecting to blynk 

}

BLYNK_WRITE(V1) //CLOSE the BLINDS

  {

    Serial.println("Closing Blinds");

    if (opened == true)

    {

    for (int c_val = 0; c_val <= 130; c_val++) //rotate in Counter-Clockwise for closing

    {

      stepper.step(c_val);

      yield();

    }

    closed = true;

    opened = false; 

    disable_motor(); // always desable stepper motors after use to reduce power consumption and heating

    }

  }

  BLYNK_WRITE(V2) // OPEN the BLINDS

  {

    Serial.println("Opening Blinds");

    if (closed == true)

    {

    for (int cc_val = 0; cc_val >= -130; cc_val--) //rotate in Clockwise for opening 

    {

      stepper.step(cc_val);

      yield();

    }

    opened = true; 

    closed = false;

    }

    disable_motor(); // always desable stepper motors after use to reduce power consumption and heating

  }

void loop()

{

  Blynk.run();

}

I’ve moved your latest topic into this one, as they are clearly related.

Lif you look back through this topic you’ll see a theme - lack of information from you about what the overall, project is trying to achieve, and lack of detail about the areas where you are seeking assistance. Your latest post is no different.
This is why you are still looking for the same assistance one month later. I’d suggest that you attempt to elaborate on the small amount of 8nformation you require, or I think you’ll still be asking the same questions in another month’s time.

Also, this is a Blynk Legacy sketch. Are you aware that Blynk Legacy will stop working altogether in 67 days?

Pete.

What will happen after 68 days, what is the plan, why will it be closed?

Pete.