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

About the control of Servo

esp8266
#1

Please tell us about the control of Servo.

Control through WiFi is possible.
Press the button to move Servo.
Servo moves but does not come back.

Servo 180 rotation 3 seconds stop 180 rotation reverse
Please tell me this code.

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

Servo servo;

char auth[] = "";
char ssid[] = "Buffalo-G-D658";
char pass[] = "";

void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);

  servo.attach(15); // NodeMCU D8 pin
  
 }
  
void loop()
{
  
  Blynk.run();
  
}
BLYNK_WRITE(V1)
{
   servo.write(param.asInt());
   {
  for ( pos = 0; pos < 180; pos += 1 ) {    myservo.write( pos );    delay( 15 );  }  for ( pos = 180; pos > 0; pos -= 1 ) {
    myservo.write( pos );
    delay( 15 );
  }
}

BLYNK_WRITE(V2)
{
  servo.write(180);
}
BLYNK_WRITE(V3)
{
  servo.write(180);
}
0 Likes

#2

I’ve edited your code so that it displays correctly.
In future, when you post code please add:

```cpp

at the top of the code and:

```

at the end of your code, otherwise the code will be deleted.

Pete.

0 Likes