Using Continuous Rotating servo with Button



Hello everyone,
I’m totally new to Arduino and coding. I’m working on one project where I need the help of yours.
I’ve one continuous rotation servo and esp8266, the idea is when I turn the button “ON” servo rotates from point A to B which take 10 seconds and deactivate there. When I turn the button “OFF” it gets activate and move to point B to A which also take 10 seconds and get deactivate there.
Please help me with the code.



Hello and Welcome to Blynk. Sorry we do not teach programming here, there are lots of other sites that do that, but we will try to help you learn about Blynk, how to find information, and answer your Blynk questions.

For starting off learning about Blynk, I recommend you start reading through the Documentation and Help Center… those links are right at the top of this page… scroll up until you see them.

For your project I recommend you start here, with a basic Servo control example…

Your continuous rotation servo will work, just act a bit differently… experiment to see how and why.

For more info, Google how continuous rotation servers are controlled via standard servo commands (I will leave the Googling part for you :wink: )

Read up on Virtual Pins…

Modify the example to use a Button and if else comparators to determine the “button” state and rotate the servo acordingly…

A code hint to get you started…

  int value = param.asInt();
  if (value == 1) {
    // rotate your servo here for 10 seconds before stopping (via timeout timer)
  } else {
    // counter rotate your servo here for 10 seconds before stopping (via timeout timer)

But, for your 10 second “delay” before shutting off the servo… do NOT use delay() but rather look into Blynk Timer and particularly the timeout() Timer that can then call the routine to stop your servo…

#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[] = "YourAuthToken";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "YourNetworkName";
char pass[] = "YourPassword";
#define OPENING 1
#define CLOSING 0
Servo s;
//Turns servo counter-clockwise (opens)
void left(Servo servo) {
//Turns servo clockwise (closes)
void right(Servo servo) {

void setup()
  // Debug console

  Blynk.begin(auth, ssid, pass);

  //Init Button
  pinMode(V3, INPUT);
  digitalWrite(V3, HIGH);
  int action = OPENING;
  int nextAction = CLOSING;
  long baseClock = 0;
      // close 
      if (nextAction == CLOSING) {
        action = CLOSING;
        baseClock = millis();

      // open 
      else  { action = OPENING;
        baseClock = millis();

void loop()

How about this? Please correct me


How about running the code on your hardware and seeing how it performs, then having a go at correcting it yourself if it doesn’t do exactly what you’re expecting?

If you get stuck then come back with some feedback about what does and doesn’t work, what you’ve tried, and what you think might be the cause of the problems that you’re experiencing.