Servo motor without slider, with button

hi, i want to make smart cat feeder with blynk.
i know example which given by blynk, but it’s working with slider.
i used arduino UNO borad and sparkfun esp8266 wifi shield

i found some codes, but it used nodemcu, so it has different code.

this is my code, it works with slider.

#include <Blynk.h>
#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#include <Servo.h>


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

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


// or Software Serial on Uno, Nano...
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(8, 9); // RX, TX

// Your ESP8266 baud rate:
#define ESP8266_BAUD 9600

ESP8266 wifi(&EspSerial);

Servo servo;
#define SERVO 5

void setup()
{
  // Set console baud rate
  Serial.begin(9600);
  delay(10);
  // Set ESP8266 baud rate
  EspSerial.begin(ESP8266_BAUD);
  delay(10);

  servo.attach(SERVO);
  Blynk.begin(auth, wifi, ssid, pass);
  
}

void loop()
{

  Blynk.run();
}

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

please help. i don’t know how to edit it to work with button.
i want to servo motor turns 30degree for 1 seconds and back to 0 degree again.

Firstly, you should be adding 3 backticks to the start and end of your code so that it formats correctly.

And secondly to answer your question You would do it in the same way as a slider but you would manually set the position.

E.g. for a single button to move to a set position on press then another position on release, set your button like this:

Or I you wanted separate buttons or a timer then you would need to be adding more code but you would just set the servo position with:

servo.write(*position_you_want*);
1 Like

The basic control code would be very similar, just use the different libraries for use with the ESP as shield instead of as standalone.

1 Like

Is this a personal project or a school assignment?

Pete.

a school project

it works ?