Servo, button and slider controll / hc-05

Hi! I’m beginner at blynk… I need a help.

I am using an arcuino uno, a HC-05, a button and 2 servos. The physical version of the program works great:

#include <Servo.h>

Servo MioServo;
Servo MioServo2;
int pulsante;
int stato;
int pot = 0;
int potOLD;
int pos;
int pos2;

void setup()
{
  Serial.begin(9600);
  pinMode(4, INPUT);
  MioServo.attach(6);
  MioServo2.attach(7);
  pinMode(13, OUTPUT);
  potOLD = pot;
}

void loop()
{
  pulsante = digitalRead(4);
  
  if (pulsante == 1)
  {
    stato = !stato;
    Serial.println ("stato = " + String(stato));
    while (pulsante == 1) pulsante = digitalRead(4);
  }

  if (stato == 0)
  {
    digitalWrite(13, LOW);
  }

  if (stato == 1)
  {
    pot = analogRead(0);
    if ((pot > (potOLD + 100) || pot < (potOLD - 100))) Serial.println("Potenziometro = " + String(pot));
    potOLD = pot;
    digitalWrite(13, HIGH);
    MioServo.write(pos);
    MioServo2.write(pos2);
    pos = map(pot, 0, 1023, 10, 165);
    pos2 = map(pot, 0, 1023, 165, 10);
    delay(15);
  }
}

I wanted to “translate” this code using blynk but i can’t do it

The logic is the button works as a “handbrake” when it is 0 the servos do not follow the potentiometer, while if it is at 1 the servos follow the potentiometer.
Someone can help me?

PS I use an android smartphone

Are you using blynk IOT or legacy ?

If IOT, then Bluetooth connection method is not supported.

I use the legacy app

You should search the forum first.

https://community.blynk.cc/search?context=topic&context_id=61050&q=Servo%20motor%20control%20&skip_context=true

I searched but I still can’t solve the problem, I’ve been looking for 3 days on the forums including this one,
unfortunately my problem is particular

Okay, try this example

i have just tried this example and it works, with a little delay (2/3 seconds).
how could i try to insert the button logic?

You mean a button that will move the servo to a specific angle ?
For example, if button is pressed, turn 90 degrees.

No, i meen that if the button is 0 the servos don’t follow the potentiometer, while if it is at 1 the servos follow the potentiometer.

I “simply” need to translate the code written above into blynk format

Okay, modify the example I sent you and add your sketch to it but without using code in the void loop, read this
https://docs.blynk.io/en/legacy-platform/legacy-articles/keep-your-void-loop-clean

i have just tried but i don’t understand how ican modify leaving the same function, i am new to the world of blynk :sweat_smile:

can you help me to modify the program?
now I try on my own, if you can give me a hand I like it very much

try this

#include <Servo.h>
#include <SoftwareSerial.h>
SoftwareSerial SwSerial(10, 11); // RX, TX
#include <BlynkSimpleSerialBLE.h>


char auth[] = " ";
BlynkTimer timer;

Servo MioServo;
Servo MioServo2;
int pulsante;
int stato;
int pot = 0;
int potOLD;
int pos;
int pos2;

void setup()
{
  Serial.begin(9600);
  SwSerial.begin(9600);
  pinMode(4, INPUT);
  MioServo.attach(6);
  MioServo2.attach(7);
  pinMode(13, OUTPUT);
  potOLD = pot;
  Blynk.begin(SwSerial, auth);
  timer.setInterval(1000L, check);
  Serial.println("Waiting for connections...");
}

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

  
void check()
{
  pulsante = digitalRead(4);
  
  if (pulsante == 1)
  {
    stato = !stato;
    Serial.println ("stato = " + String(stato));
    while (pulsante == 1) pulsante = digitalRead(4);
  }

  if (stato == 0)
  {
    digitalWrite(13, LOW);
  }

  if (stato == 1)
  {
    pot = analogRead(0);
    if ((pot > (potOLD + 100) || pot < (potOLD - 100))) Serial.println("Potenziometro = " + String(pot));
    potOLD = pot;
    digitalWrite(13, HIGH);
    MioServo.write(pos);
    MioServo2.write(pos2);
    pos = map(pot, 0, 1023, 10, 165);
    pos2 = map(pot, 0, 1023, 165, 10);
    delay(15);
  }
}

Arduino give me this error:

C:\Users\falbo.l\Downloads\Arduino_StepperMotor_Potentiometer_Buttons\Arduino_StepperMotor_Potentiometer_Buttons.ino: In function 'void setup()':
Arduino_StepperMotor_Potentiometer_Buttons:26:3: error: 'SerialBLE' was not declared in this scope
   SerialBLE.begin(9600);
   ^~~~~~~~~
C:\Users\falbo.l\Downloads\Arduino_StepperMotor_Potentiometer_Buttons\Arduino_StepperMotor_Potentiometer_Buttons.ino:26:3: note: suggested alternative: 'Serial'
   SerialBLE.begin(9600);
   ^~~~~~~~~
   Serial
Più di una libreria trovata per "Servo.h"
Usata: \\Serverone\studenti\falbo.l\Documenti\Arduino\libraries\Servo
Non usata: C:\Program Files (x86)\Arduino\libraries\Servo
Più di una libreria trovata per "BlynkSimpleSerialBLE.h"
Usata: \\Serverone\studenti\falbo.l\Documenti\Arduino\libraries\blynk-library-master
Non usata: \\Serverone\studenti\falbo.l\Documenti\Arduino\libraries\Blynk
exit status 1
'SerialBLE' was not declared in this scope

and the HC-05 does not activate, the led on the card remains off

i try to change serialBLE with SwSerial

I modified it, give it a try.

I beg your pardon, I am explained badly before.
My goal is to bring both the slider and the button to blynk not just the button

the virtual button activates and deactivates the virtual slider both on blynk

What about the sketch, does it work ?

No, when i send the sketch to arduino the HC05 doesn’t send/recive signal

Do you have the BT widget installed in the Blynk app, and what do you see when you open that widget?

Pete.

I’ve modified it again, try it one last time.