BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Control stepper motor with slider or joystick

    #define BLYNK_PRINT Serial    // Comment this out to disable prints and save space

    #include <SPI.h>
    #include <Ethernet.h>
    #include <BlynkSimpleEthernet.h>

    #define W5100_CS  10
    #define SDCARD_CS 4

    #include <Stepper.h>
    const int stepsPerRevolution = 200;  // change this to fit the number of steps per revolution
    Stepper myStepper( stepsPerRevolution, 14, 15, 16, 17 );

    int previous = 0;
     
    // Insert Auth Token from the Blynk App.
    char auth[] = "xxxxxxxxxxxxxxxxxxxxx";

    void setup()
    {
      pinMode(SDCARD_CS, OUTPUT);
      digitalWrite(SDCARD_CS, HIGH); // Deselect the SD card
      
       // set the speed at 60 rpm:
      myStepper.setSpeed(60);
     
      Serial.begin(9600);
      Blynk.begin(auth);  
     
      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();
      }
    }


    BLYNK_WRITE(V3)  // 
    {
          //use this for joystik 
      // int steps = param[0].asInt();  
      // int    s1 = param[1].asInt();

          //use this for slider
       int steps = param.asInt(); 
      
      if ( steps != 0  )
      {
      // step one step:
      myStepper.step(steps - previous );
      Serial.print("steps:");
      Serial.println(steps);  //(stepCount);
      
      delay(500);
      previous = steps;
      }
    }

    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);
    }

So … your question is … what exactly? I assume something is not working, otherwise you wouldn’t post here.

ProTip 1: get rid of the delays :slight_smile:

Sorry I forgot the question … when I execute the command with the slider it locks the sketch … only when I use the slider.4

And how to use the joystick with a servo and a stepper motor together?

I’d get rid of the delays first. They are probably causing at least some problems, if not now, then maybe later.

I think your commented out parts for the joystick are pretty much correct from what I can tell.

Thank you, I’m going to take a test here.

The worst that could happen is probably some non-working stuff, but we’ll figure it out :slight_smile:

Without the delays it works perfectly thank you.

1 Like

@bud can you tell me why you have used
#define W5100_CS 10
#define SDCARD_CS 4
Reasons
I have 6 wires stepper motor and i want to control it with H bridge through blynk
Also tell whether you used buttons V1 V2 in interface or something else
Pls respond…

@ManiYr07 Welcome to Blynk forum. Please take note of the time date stamps BEFORE posting… this topic is over a year old and the OP hasn’t been active for almost as long :stuck_out_tongue_winking_eye:

The commands you are asking about are part of the Ethernet shield library… if you don’t use one, don’t use them :slight_smile:

Read through the Documentation, Help Center pages and try out the Sketch Builder examples (All links at the top of this page) in-order to get a better understanding of what the vPins are used for.

If you have further questions about your project, please create a new topic and supply lots of details on what you have ALREADY accomplished as our (other members) goal here is to assist in your learning about Blynk, not teach you programming or make it for you.

Thank you.

@ManiYr07 you are in luck… the OP is back :slight_smile:

1 Like

Thanks for reopening the topic @GunnerTechTools

#define W5100_CS 10 = pin that defines the communication with the W5100 shield
#define SDCARD_CS 4 = pin that defines communication with the sd card slot of the W5100 shield

The commands performed between the interface and the code in arduino are all made with virtual pins.
Inside the code it interprets the virtual pins and sends to the physical pins of the arduino according to the command.
Sliding buttons were used in this case.

Sorry for not being exact in the answer, because it has been more than a year of this project and I do not remember much of the interface,
but if you read and interpret my code you will understand

1 Like

Can you help me out here…
@GunnerTechTools Very thankful to you…

@ManiYr07 No need to post help requests in others topics (this is one reason why I close old topics :stuck_out_tongue_winking_eye: ) as everyone can already see your relevant topic… continuing discussion over there.