Servo Speed

Hi I need help please.
Im using bynk app to controll 2 Servos. But I want them to run with diffrent speed.
does anyone have a simple solution?

here is my working code so far:

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Servo.h>

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

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

Servo servo;

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

Servo servo2;

BLYNK_WRITE(V4)
{
  servo2.write(param.asInt());

}

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

  Blynk.begin(auth, ssid, pass);

  servo.attach(4);
  servo2.attach(5);
}

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

controlling servo speed is really crude system i think. Your codes might change according to your servo type.

I did some projects about sg90 servo speed. I used for loop to change degree and i added delay in loop.

for example,

for(int x = 0; x<=180; x++) {
 servo.write(x);
delay(100);
}

if you increase delay, your servo will turn slowly but low res.

some servos can move slowly by decreasing vcc voltage

thank you for your help! unfortunately your advice doesnt work. maybe because my servo turns 270 degree?

just edit for loop. this loop will work until variable x reaches 180. make it 270.

and also you can change increment details. linear or parabolic curves you can add…

still not working… can u see whats wrong? thx!

Servo servo;

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

Servo servo2;

BLYNK_WRITE(V4)
{
  servo2.write(param.asInt());

}

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

  Blynk.begin(auth, ssid, pass);
 

  servo.attach(4);
  servo2.attach(5);
}

void loop()
{
  Blynk.run();
for(int x = 0; x<=270; x++) {
 servo.write(V4);
delay(200);

Please properly format all posted code as per forum instructions.

BTW, this is not really a Blynk related topic, more like “how to code something”… lots of info via Google. :wink:

As far as integrating such option into Blynk… stay away from delays, use timers… (and search this forum :stuck_out_tongue_winking_eye: )

1 Like

seems like you didnt get what i want. i cant translate your example to my problem. i dont want the servo to move by itself. i want to control the angle with a slider and it should move slow all the time. help would be much apprechiated

I ‘got’ exactly what you want :wink: but servos don’t have speed control, they have position control.

If you want slower speed you control the rate of incremental position.

My example shows how to do that without delays… it is not intended to work for your exact need, but give you something to work from.

hi, do you think something like this could work? (still not working properly)
regards

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Servo.h>

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

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

Servo servo;

BLYNK_WRITE(V3)
{
  servo.write(param.asInt());
}
const int targetPin =  4;
const int servoDuration = 10; // number of millisecs that servo is on
const int interval = 10; // number of milisecs when the servo is off


//------------ VARIABLES (will change)---------------------

byte targetservoState = servo.attach(4); // this variable is necesary to help arduino monitor the status of servo
                            //the initial condition (t=0) can be either run or stop
unsigned long currentMillis = 0;    // stores the value of millis() in each iteration of loop()
unsigned long previousservoMillis = 0;   // will store last time the servo was updated


//========== THE SETUP ==============================

void setup() {
  // Debug console 
  Serial.begin(9600); //default comm speed between arduino and serial monitor. no need to change.
  Serial.println("servoMillis.ino");  // so we know what sketch is running
  pinMode(targetPin, OUTPUT);
  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8442);




}

//========== THE LOOP ==============================

void loop() {
 
  Blynk.run();

  
  currentMillis = millis();   // capture the latest value of millis()
                              // this is equivalent to noting the time from a clock
  updateTargetservo();  //monitoring status of servo and do approproate actions

}

//------------ OTHER FUNCTIONS ---------------------

void updateTargetservo() {

  if (targetservoState == servo.attach(0)) { //if the servo is OFF
     Serial.println("detach()");
    if ((unsigned long) currentMillis - previousservoMillis >= interval) { 
      targetservoState = servo.attach(4);
      digitalWrite(targetPin, targetservoState);
      // and save the time when we made the change
      previousservoMillis += interval;
      // NOTE: The previous line could alternatively be
      //        previousservoMillis = currentMillis
      //        Adding on the interval is a better way to ensure that succesive periods are identical
    }
  }
  else {  // i.e. if  servoState is run (if the servo is ON)
    Serial.println("servo.attach(4)");
    if ((unsigned long) currentMillis - previousservoMillis >= servoDuration) {
      targetservoState = servo.attach(0);
      digitalWrite(targetPin, targetservoState);
      // and save the time when we made the change
      previousservoMillis += servoDuration;
      // NOTE: The previous line could alternatively be
      //        previousservoMillis = currentMillis
      //        Adding on the duration is a better way to ensure that succesive periods are identical
    }
  }
}

I can help you. :upside_down_face:

This is a 3 year old topic, and @Lisa hasn’t been seen on the forum for almost 2 years.

Pete.

I still here and still hoping for a solution

Yes please

I am doing a project about control two servos with smooth motion
You can use this code my friend


  Rotate a servo using a slider!

  App project setup:
    Slider widget (0...180) on V3
 *************************************************************/

// Template ID, Device Name and Auth Token are provided by the Blynk.Cloud
// See the Device Info tab, or Template settings
//#define BLYNK_TEMPLATE_ID           "TMPLxxxxxx"
//#define BLYNK_DEVICE_NAME           "Device"
#define BLYNK_AUTH_TOKEN            " bt8OxIoRjwRybxxxxxxxxxxxx"


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


#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Servo.h>

char auth[] = BLYNK_AUTH_TOKEN;

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "TecH BoyS ToyS";
char pass[] = "techboystoys@xxxxx";

Servo servo1;
Servo servo2;
int poss = 0;
int poss2 = 70;

BLYNK_WRITE(V1)
{
 
  int x = param.asInt();
  if(x == HIGH){
  for(x = 1; x<=140; x++) {
 servo1.write(x);
delay(30);
}
}
else{
  for(x = 140; x>=0; x--) {
 servo1.write(x);
delay(30);
}
}}
BLYNK_WRITE(V2)
{
 
  int y = param.asInt();
  if(y == HIGH){
  for(y = 70; y>=00; y--) {
 servo2.write(y);
delay(30);
}
}
else{
  for(y = 0; y<=70; y++) {
 servo2.write(y);
delay(30);
}
}}
void setup()
{
  // Debug console
  Serial.begin(115200);

  Blynk.begin(auth, ssid, pass);
servo1.write(poss);
  servo1.attach(5);
 servo2.write(poss2);
  servo2.attach(4);

}

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

//You must change delay according to your need

Thank you! But i still struggle to make the motion smooth both ways.