BLYNK
BLYNK.IO       📲 GETTING STARTED       📗 DOCS       👉 SKETCH BUILDER

Como puedo parar un servomotor de 360°

Hola, no sé como puedo hacer para que mi servomotor gire 2 segundos en sentido anti horario (botón V1) y luego pare, y que después apretando V2 gire en sentido horario 2 segundos y pare. Sólo puedo hacer que vaya de una dirección a otra, pero no hacer que se detenga. O bien que gire en direccion anti horaria apretando V1 y luego apretar V2 para que se detenga y que gire en sentido horario cuando presione V3.

#define BLYNK_TEMPLATE_ID           "TMPLjrLCHD7R"
#define BLYNK_DEVICE_NAME           "Quickstart Device"
#define BLYNK_AUTH_TOKEN            "z6oDvz0HyzjEBXuKyLkoG67J5VogShkZ"
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Servo.h>

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

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

char auth[] = BLYNK_AUTH_TOKEN;

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Javi";
char pass[] = "Contraseñaxd";

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

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

  Blynk.begin(auth, ssid, pass);



  servo.attach(2); // NodeMCU D8 pin

}

void loop()
{
  Blynk.run();
  // You can inject your own code or combine it with other sketches.
  // Check other examples on how to communicate with Blynk. Remember
  // to avoid delay() function!
}



BLYNK_WRITE(V1)

{

   servo.writeMicroseconds(500);

}



BLYNK_WRITE(V2)

{

  servo.writeMicroseconds(1500);

}

BLYNK_WRITE(V3)

{

  servo.writeMicroseconds(1550);

}

A continuous rotation servo motor can be controlled by calling the servo.writeMicroseconds() function, which typically accepts values from 1000-2000. A value of 1000 should rotate the motor counter-clockwise at full speed. A value of 2000 should rotate the motor clockwise at full speed. A value of 1500 should cause the motor to stop rotating (and without any vibration). Intermediate values can be used to change the speed of the rotation.

// rotate counter-clockwise full-speed
servo.writeMicroseconds(1000);

// rotation stopped
servo.writeMicroseconds(1500);

// rotate clockwise full-speed
servo.writeMicroseconds(2000);

If necessary, you can fine-tune the values listed above based on testing with your actual servo motor. You could go as low as 700 or as high as 2300.
CAUTION: If you adjust the endpoint values too far (too low or too high), you might damage the motor.

If you need your servo to only rotate for a specific period of time, then simply use a blynk timeout timer (instead of delay function), something like this

servo.writeMicroseconds(2000); // rotate clockwise
timer.setTimeout(2000L, []() 
  {  
servo.writeMicroseconds(1500); // stop rotation
  }); 
2 Likes

thank you, very much. I’m gonna try it!