How to setup servo to make multiple movements

I’m trying to make a servo have multiple positions with the press of just one blynk button. Let’s say I want it to go forward a little the backward a little then maybe back forward some all with just one button press. Is this possible if so where would I enter in the servo positions… In the void loop after Blynk.run? Or where? I know how to setup a button and make it move my servo. I just want it to move multiple times.

Yes, it is possible, and way to many ways to do it to mention them all…

But one would be to precode a servo movement routine that runs whenever you press a button, set to a vPin, that calls a BLYNK_WRITE() function containing the movement routine.

1 Like

When I precode the servo movement I wanna use would I put that in void setup or void loop. If I put it in void loop wouldn’t that make it keep doing it and I only want it to do it one time.

You use what is sometimes called Functions… either a separate one or without a Blynk one


BLYNK_WRITE(vPin){
   if (param.asInt == 1){  // If Button is ON
    moveServo();  // Run servo function
}

void moveServo() {
// do servo stuffs
}

BLYNK_WRITE(vPin){
   if (param.asInt == 1){  // If Button is ON
   // do servo stuffs

   // the following else is optional
   else {  // If Button is OFF
   // do something else if wanted
   }
}
1 Like

This is my code. It keeps loading with a error. I’m trying to input my servo movement but not sure where to put it in?

#define BLYNK_PRINT Serial


#include <SoftwareSerial.h>
SoftwareSerial SwSerial(10, 11); // RX, TX
    
#include <BlynkSimpleSerialBLE.h>
#include <SoftwareSerial.h>
#include <Servo.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "7f5490246cd342a583d5c15b5251fe81";

SoftwareSerial SerialBLE(10, 11); // RX, TX

Servo servo;

BLYNK_WRITE(V3)
{
  servo.write(param.asInt());
  }
BLYNK_WRITE(V3){
  if (param.asInt() == 1){

}
void moveServo(){
}
void setup()
{
  // Debug console
  Serial.begin(9600);

  SerialBLE.begin(9600);
  Blynk.begin(SerialBLE, auth);

  Serial.println("Waiting for connections...");

  servo.attach(8);
  pinMode(8, OUTPUT);
  
}

void loop()
{
  Blynk.run();
  
}

I already showed you example ideas to study and learn… don’t just copy paste them in as you will have problems with things like duplicate BLYNK_WRITE() functions… as you have done :stuck_out_tongue_winking_eye:

If you don’t already know how to control a servo with code, then you need to learn… Google for that… Blynk doesn’t actually control them, Servo libraries and code does, Blynk just supplies an alternative interface.

1 Like