Problems with Bluetooth HC-05 I need filter?

Well, to put you a little situation:

I'm doing a project of a drone controlled by Arduino UNO and this controlled from a mobile.
(The project also used a gyroscope IMU accelerometer MPU-6050 and ESC for my brusheless motors).

The project works perfectly when I check directly with the computer, but the problem comes when control it with the Bluetooth, as I start to send data from my mobile, (although these data have nothing to do with the program and I continue controlling it from my computer), the motors start to move randomly, with small pulses when I command to be "quiet" and when I command to go at some speed they do, but they have peaks of speed, so i cant controll them.

I guess that this is a problem with the Bluetooth that produces noise or something, I would like to know if someone has happened something similar, or have any theory that may be happening.

I apologize for my English, I know it's not very good.


Bien, para poneros un poco en situacion:

Estoy haciendo un proyecto de un dron controlado por arduino UNO y este controlado desde un movil.
(En el proyecto tambien uso un IMU giroscopio acelerometro MPU-6050 y unos ESC para pasar de CC de la bateria a trifasica de mis motores).

El proyecto funciona perfectamente cuando lo controlo directamente con el ordenador, pero el problema viene a la hora de controlarlo con el Bluetooth, en cuanto empiezo a mandar datos desde mi móvil, (aunque estos datos no tengan nada que ver con el programa y siga controlandolo desde mi ordenador), los motores empiezan a moverse de forma aleatoria, con pequeños pulsos cuando les mando estar "quietos" y cuando les mando acelerar estos no van a la velocidad deseada sino que van oscilando en torno a esta.

Supongo que se trata de algún problema con el Bluetooth que produce ruido o algo, querría saber si a alguien le ha pasado algo similar, o tiene alguna teoría de que puede estar pasando.

Seems to be a timing problem. How do you generate the PWM signal for the ESCs?
Also, please post your code using the code tags (</>-Button).

lg, couka

I use servo.h for the ESC

but as i say this code works perfect:

#include<Servo.h>

//acelerometro grioscopio
#include <Wire.h>
#define  BAUD 9600   //velocidad puerto serial   funciona hasta 38400
//Direccion I2C de la IMU
#define MPU 0x68

 
//Ratios de conversion
#define A_R 16384.0
#define G_R 131.0
 
//Conversion de radianes a grados 180/PI
#define RAD_A_DEG = 57.295779

 
Servo motor1, motor2, motor3, motor4; //Crear un objeto de clase servo

int16_t AcX, AcY, AcZ, GyX, GyY, GyZ;
int vel = 1000; //amplitud del pulso
int i,j,k,l=1000;
int a,b=0;
int aceleracion;
int media;
byte recibiendoByte ;
boolean iniciado = false; 
int vel1;

//Angulos
float Acc[2];
float Gy[2];
float Angle[2];

void setup()
{
  Serial.begin(BAUD);
  Wire.begin();
  Wire.beginTransmission(MPU);
  Wire.write(0x6B);
  Wire.write(0);
  Wire.endTransmission(true);
  
  //Asignar un pin al ESC
  motor1.attach(9);
  motor2.attach(10);
  motor3.attach(6);
  motor4.attach(5);
  
   
   Serial.println (" Conecte la bateria \n una vez conectada escuchara una serie de pitidos \n pulse 'A' para arrancar");
   while ( iniciado==false ){
          
          recibiendoByte = Serial.read(); // Leemos el Byte recibido
          if (recibiendoByte == 65 || recibiendoByte ==97) {    // A o a  Mayusculas o minusculas
              iniciado=true;

                                
                              
                                Serial.println(" Escuchara un pitido de confirmacion y varios pitidos que indican el numero de celulas de la bateria ");
                                //Activar el ESC
                                 motor1.writeMicroseconds(1000); //1000 = 1ms
                                 motor2.writeMicroseconds(1000);
                                 motor3.writeMicroseconds(1000);
                                 motor4.writeMicroseconds(1000);
                                  //Cambia el 1000 anterior por 2000 si
                                //tu ESC se activa con un pulso de 2ms
                                
 
                                   
                                  delay(5000); //Esperar 5 segundos para hacer la activacion
                                            
            
            
            }
   }
 
   
 
  Serial.println(" Motor preparado ") ;
 Serial.println(" escriva la velocidad (1000-2000) ");
 Serial.setTimeout(10);   
 
}
 
void loop()
{

   //Leer los valores del Acelerometro de la IMU
   Wire.beginTransmission(MPU);
   Wire.write(0x3B); //Pedir el registro 0x3B - corresponde al AcX
   Wire.endTransmission(false);
   Wire.requestFrom(MPU,6,true); //A partir del 0x3B, se piden 6 registros
   AcX=Wire.read()<<8|Wire.read(); //Cada valor ocupa 2 registros
   AcY=Wire.read()<<8|Wire.read();
   AcZ=Wire.read()<<8|Wire.read();
 
    //Se calculan los angulos Y, X respectivamente.
   Acc[1] = atan(-1*(AcX/A_R)/sqrt(pow((AcY/A_R),2) + pow((AcZ/A_R),2)))*RAD_TO_DEG;
   Acc[0] = atan((AcY/A_R)/sqrt(pow((AcX/A_R),2) + pow((AcZ/A_R),2)))*RAD_TO_DEG;
 
   //Leer los valores del Giroscopio
   Wire.beginTransmission(MPU);
   Wire.write(0x43);
   Wire.endTransmission(false);
   Wire.requestFrom(MPU,4,true); //A diferencia del Acelerometro, solo se piden 4 registros
   GyX=Wire.read()<<8|Wire.read();
   GyY=Wire.read()<<8|Wire.read();
 
   //Calculo del angulo del Giroscopio
   Gy[0] = GyX/G_R;
   Gy[1] = GyY/G_R;
 
   //Aplicar el Filtro Complementario
   Angle[0] = 0.98 *(Angle[0]+Gy[0]*0.010) + 0.02*Acc[0];
   Angle[1] = 0.98 *(Angle[1]+Gy[1]*0.010) + 0.02*Acc[1];
 
   //Mostrar los valores por consola
//   Serial.print("Angle X: "); Serial.print(Angle[0]); Serial.print("\n");
//   Serial.print("Angle Y: "); Serial.print(Angle[1]); Serial.print("\n------------\n");

// indicamos la velocidad de los motores angulo Z   
//vel1 existe porque entra dos veces al bucle
  if(Serial.available() > 0)
  {
    vel1 = Serial.parseInt(); //Leer un entero por serial
    Serial.print(vel);
    if(vel1 != 0)
    {
      vel=vel1;
// calculamos la media de los valores i j k l       
      media=(i+j+k+l)/4;
// medimos cual es la "aceleracion" para calcular la diferencia entre la velociad deseada y los valores actuales
      aceleracion=vel-media;
      l=l+aceleracion; 
      i=i+aceleracion;
      j=j+aceleracion;
      k=k+aceleracion;
      
     
       Serial.print("dando velocidad ");
    }
  }
  delay(10); //Nuestra dt sera, pues, 0.010, que es el intervalo de tiempo en cada medida




// Estabilidad angulo X
    if( Angle[0]-a>2.5)
      {
        i++,j++,k--,l--;
        Serial.print("Angle X+ ");Serial.print("\n");
        
      }
    if( Angle[0]-a<-2.5)
      {
        i--,j--,k++,l++;
        Serial.print("Angle X- ");Serial.print("\n");
        
      }   
//    if( Angle[0]-a>10)
//      {
//        i=i+5,j=j+5,k=k-10,l=l-10;
//      }
//    if( Angle[0]-a<-10)
//      {
//        i=i-10,j=j-10,k=k+10,l=l+10;
//      }   
//    if( Angle[0]-0>20)
//      {
//         i=i+10,j=j+10,k=k-10,l=l-10;
//         Serial.print("Angle X+20 ");Serial.print("\n");
//      }
//    if( Angle[0]-0<-20)
//      {
//        i=i-10,j=j-10,k=k+10,l=l+10;
//        Serial.print("Angle X-20 ");Serial.print("\n");
//      }   


// Estabilidad angulo y        
    if( Angle[1]-b > 2.5)
      {
        i++,j--,k++,l--;
        Serial.print("Angle Y+ ");Serial.print("\n");
      }
    if( Angle[1]-b < -2.5)
      {
        i--,j++,k--,l++;
        Serial.print("Angle Y- ");Serial.print("\n");
      }
//   if( Angle[1]-a>10)
//      {
//        i=i+10,j=j-10,k=k+10,l=l-10;
//      }
//    if( Angle[1]-a<-10)
//      {
//        i=i-10,j=j+10,k=k-10,l=l+10;
//      }   
//    if( Angle[1]-0>20)
//      {
//        i=i+10,j=j-10,k=k+10,l=l-10;
//        Serial.print("Angle Y+20 ");Serial.print("\n");
//      }
//    if( Angle[1]-0<-20)
//      {
//        i=i-10,j=j+10,k=k-10,l=l+10;
//        Serial.print("Angle Y-20 ");Serial.print("\n");
//      }



// marcar maximos y minimos
         
if( i>1500)
{i=1500;
  }
if (i<1000)
{i=1000;
  }

if( j>1500)
{j=1500;
  }
if (j<1000)
{j=1000;
  }

if( k>1500)
{k=1500;
  }
if (k<1000)
{k=1000;
  }
  
if( l>1500)
{l=1500;
  }
if (l<1000)
{l=1000;
  }


if( Angle[0]-a<2.5 && Angle[0]-a>-2.5&&  Angle[1]-b<2.5 &&  Angle[1]-b>-2.5)
{
  i=vel;
  j=vel;
  k=vel;
  l=vel;
   Serial.print("estabilizado");
  }
  
motor1.writeMicroseconds(i);      
motor2.writeMicroseconds(j);
motor3.writeMicroseconds(k);
motor4.writeMicroseconds(l);
}

but this works random

this works random

//Bluetooth
#include <SoftwareSerial.h>
//motores
#include<Servo.h>
//acelerometro grioscopio
#include <Wire.h>

#define  BAUD 9600   //velocidad puerto serial   funciona hasta 38400
//Direccion I2C de la IMU
#define MPU 0x68

 
//Ratios de conversion
#define A_R 16384.0
#define G_R 131.0
 
//Conversion de radianes a grados 180/PI
#define RAD_A_DEG = 57.295779

// conexiones bluetooth
#define TxD 7
#define RxD 8
#define EN 2
//VCC -->5V

// conexiones giroscopio

//VCC -->5V
//GND -->GND
//(Valores pod defecto en la libreria) 
//SCL -->A5
//SDA -->A4 




SoftwareSerial Bluetooth(TxD,RxD); //cambiar las posiciones TxD y RxD por 
 
Servo motor1, motor2, motor3, motor4; //Crear un objeto de clase servo

int16_t AcX, AcY, AcZ, GyX, GyY, GyZ;
int vel = 1000; //amplitud del pulso
int i,j,k,l=1000;
int a,b=0;
int aceleracion;
int media;
byte recibiendoByte ;
boolean iniciado = false; 
//int vel1;
int dato = 0;
int desconexion = 0;

//Angulos
float Acc[2];
float Gy[2];
float Angle[2];

void setup()
{
  
  Serial.begin(BAUD);

  Bluetooth.begin(BAUD);
  
  Wire.begin();
  Wire.beginTransmission(MPU);
  Wire.write(0x6B);
  Wire.write(0);
  Wire.endTransmission(true);

  //Asignar pines bluetooth
   pinMode(EN ,OUTPUT);
   

   
  //Asignar un pin al ESC
  motor1.attach(9);
  motor2.attach(10);
  motor3.attach(6);
  motor4.attach(5);

  //Preparar Bluetooth
  digitalWrite(EN,HIGH);
 
    
   
   
   while ( iniciado==false ){
          
          recibiendoByte = Bluetooth.read(); // Leemos el Byte recibido
          if (recibiendoByte == 65) 
          {    
              iniciado=true;

                                
                                //Activar el ESC
                                 motor1.writeMicroseconds(1000); //1000 = 1ms
                                 motor2.writeMicroseconds(1000);
                                 motor3.writeMicroseconds(1000);
                                 motor4.writeMicroseconds(1000);
                                  //Cambia el 1000 anterior por 2000 si
                                  //tu ESC se activa con un pulso de 2ms
                                
                                    
                                  delay(5000); //Esperar 5 segundos para hacer la activacion
                                            
            
            
            }
   }
 
  
 
  
 
}

  
void loop()
{

   //Leer los valores del Acelerometro de la IMU
   Wire.beginTransmission(MPU);
   Wire.write(0x3B); //Pedir el registro 0x3B - corresponde al AcX
   Wire.endTransmission(false);
   Wire.requestFrom(MPU,6,true); //A partir del 0x3B, se piden 6 registros
   AcX=Wire.read()<<8|Wire.read(); //Cada valor ocupa 2 registros
   AcY=Wire.read()<<8|Wire.read();
   AcZ=Wire.read()<<8|Wire.read();
 
    //Se calculan los angulos Y, X respectivamente.
   Acc[1] = atan(-1*(AcX/A_R)/sqrt(pow((AcY/A_R),2) + pow((AcZ/A_R),2)))*RAD_TO_DEG;
   Acc[0] = atan((AcY/A_R)/sqrt(pow((AcX/A_R),2) + pow((AcZ/A_R),2)))*RAD_TO_DEG;
 
   //Leer los valores del Giroscopio
   Wire.beginTransmission(MPU);
   Wire.write(0x43);
   Wire.endTransmission(false);
   Wire.requestFrom(MPU,4,true); //A diferencia del Acelerometro, solo se piden 4 registros
   GyX=Wire.read()<<8|Wire.read();
   GyY=Wire.read()<<8|Wire.read();
 
   //Calculo del angulo del Giroscopio
   Gy[0] = GyX/G_R;
   Gy[1] = GyY/G_R;
 
   //Aplicar el Filtro Complementario
   Angle[0] = 0.98 *(Angle[0]+Gy[0]*0.010) + 0.02*Acc[0];
   Angle[1] = 0.98 *(Angle[1]+Gy[1]*0.010) + 0.02*Acc[1];
 
   



// leemos el dato que entre por el bluetooth y lo almacenamos en la variable "dato" para poder clasificarlo
dato = Bluetooth.read();
// .read envia un -1 si no lee nada

//descenso controlado si pierde señal
    if (dato == -1)
    {
       Serial.println("sumando" ) ;
       desconexion++;
       iniciado=false;
       recibiendoByte=0;
        if (desconexion>50)
        {
          Serial.println(desconexion) ;
          
          while ((i>1000)||(j>1000)||(k>1000)||(l>1000))
              {
               i=i-20;
               j=j-20;
               k=k-20;
               l=l-20;
               motor1.writeMicroseconds(i);      
               motor2.writeMicroseconds(j);
               motor3.writeMicroseconds(k);
               motor4.writeMicroseconds(l);
               Serial.println(" desconexion ") ;
              
               }
          while ( iniciado==false )
             {
              Serial.println(" bucle iniciado ") ;
                  recibiendoByte = Bluetooth.read(); // Leemos el Byte recibido
                  if (recibiendoByte == 65) 
                  {    
                      iniciado=true;
        
                                        
                                        //Activar el ESC
                                         motor1.writeMicroseconds(1000); //1000 = 1ms
                                         motor2.writeMicroseconds(1000);
                                         motor3.writeMicroseconds(1000);
                                         motor4.writeMicroseconds(1000);
                                          //Cambia el 1000 anterior por 2000 si
                                          //tu ESC se activa con un pulso de 2ms
                                        
                      desconexion=0;                      
                                          delay(5000); //Esperar 5 segundos para hacer la activacion
                                                    
                    
                    
                    }
             }  

                
        }
    }
    if (dato != -1)
    {
      // eje x
      if (dato<21)

      {
        a=dato-10;
      }
      // eje y
      if (dato>21 && dato<51)

      {
        b=dato-40;
      }
      //velocidad
      if (dato>99 && dato<151)
       {
        desconexion=0;
        // le dato entra entre 100 y 150, pero nosotros lo queremos entre 1000 y 1500
        vel=dato*10;

        //marcar un minimo para que los motores no tengan una señal de poca fuerza en la que no pueden ni arrancar ni pararse
          if(vel<1070)
            {
              vel=1000;
            }
            // calculamos la media de los valores i j k l       
        media=(i+j+k+l)/4;
            // medimos cual es la "aceleracion" para calcular la diferencia entre la velociad deseada y los valores actuales
        aceleracion=vel-media;
        i=i+aceleracion;
        j=j+aceleracion;
        k=k+aceleracion;
        l=l+aceleracion; 
      }
    
    
    }
  
  delay(10); //Nuestra dt sera, pues, 0.010, que es el intervalo de tiempo en cada medida




// Estabilidad angulo X
    if( Angle[0]-a>2)
      {
        i++,j++,k--,l--;
        Serial.print("Angle X+ ");Serial.print("\n");
        
      }
    if( Angle[0]-a<-2)
      {
        i--,j--,k++,l++;
        Serial.print("Angle X- ");Serial.print("\n");
        
      }   
   

// Estabilidad angulo y        
    if( Angle[1]-b > 2)
      {
        i++,j--,k++,l--;
        Serial.print("Angle Y+ ");Serial.print("\n");
      }
    if( Angle[1]-b < -2)
      {
        i--,j++,k--,l++;
        Serial.print("Angle Y- ");Serial.print("\n");
      }
   



// marcar maximos y minimos
         
if( i>1500)
{i=1500;
  }
if (i<1000)
{i=1000;
  }

if( j>1500)
{j=1500;
  }
if (j<1000)
{j=1000;
  }

if( k>1500)
{k=1500;
  }
if (k<1000)
{k=1000;
  }
  
if( l>1500)
{l=1500;
  }
if (l<1000)
{l=1000;
  }


if( Angle[0]-a<2 && Angle[0]-a>-2 &&  Angle[1]-b<2 &&  Angle[1]-b>-2)
{
  i=vel;
  j=vel;
  k=vel;
  l=vel;
  Serial.println(" estabilizado") ;
  }
  
motor1.writeMicroseconds(i);      
motor2.writeMicroseconds(j);
motor3.writeMicroseconds(k);
motor4.writeMicroseconds(l);
}

and I used this to detect the problem arises only connect the bluetooth, is the same code as the first, only allowing the bluetooth connect.

#include <SoftwareSerial.h>

#define TxD 7
#define RxD 8
#define EN 2

int dato = 0;
// cambiamos los pines de rxd y txd
SoftwareSerial Bluetooth(TxD,RxD); // RX, TX recorder que se cruzan







#include<Servo.h>


//acelerometro grioscopio
#include <Wire.h>
#define  BAUD 9600   //velocidad puerto serial   funciona hasta 38400
//Direccion I2C de la IMU
#define MPU 0x68

 
//Ratios de conversion
#define A_R 16384.0
#define G_R 131.0
 
//Conversion de radianes a grados 180/PI
#define RAD_A_DEG = 57.295779

 
Servo motor1, motor2, motor3, motor4; //Crear un objeto de clase servo

int16_t AcX, AcY, AcZ, GyX, GyY, GyZ;
int vel = 1000; //amplitud del pulso
int i,j,k,l=1000;
int a,b=0;
int aceleracion;
int media;
byte recibiendoByte ;
boolean iniciado = false; 
int vel1;

//Angulos
float Acc[2];
float Gy[2];
float Angle[2];

void setup()
{
  
  
  
  
  Bluetooth.begin(BAUD);
       pinMode(EN ,OUTPUT);
      

      digitalWrite(EN,HIGH);

  
  
  
  
  
  
  
  Serial.begin(BAUD);
  Wire.begin();
  Wire.beginTransmission(MPU);
  Wire.write(0x6B);
  Wire.write(0);
  Wire.endTransmission(true);
  
  //Asignar un pin al ESC
  motor1.attach(9);
  motor2.attach(10);
  motor3.attach(6);
  motor4.attach(5);
  
   
   Serial.println (" Conecte la bateria \n una vez conectada escuchara una serie de pitidos \n pulse 'A' para arrancar");
   while ( iniciado==false ){
          
          recibiendoByte = Serial.read(); // Leemos el Byte recibido
          if (recibiendoByte == 65 || recibiendoByte ==97) {    // A o a  Mayusculas o minusculas
              iniciado=true;

                                
                              
                                Serial.println(" Escuchara un pitido de confirmacion y varios pitidos que indican el numero de celulas de la bateria ");
                                //Activar el ESC
                                 motor1.writeMicroseconds(1000); //1000 = 1ms
                                 motor2.writeMicroseconds(1000);
                                 motor3.writeMicroseconds(1000);
                                 motor4.writeMicroseconds(1000);
                                  //Cambia el 1000 anterior por 2000 si
                                //tu ESC se activa con un pulso de 2ms
                                
 
                                   
                                  delay(5000); //Esperar 5 segundos para hacer la activacion
                                            
            
            
            }
   }
 
   
 
  Serial.println(" Motor preparado ") ;
 Serial.println(" escriva la velocidad (1000-2000) ");
 Serial.setTimeout(10);   
 
}
 
void loop()
{

   {
    dato = Bluetooth.read();
    // .read devuelve -1 si  no hay nada
    if (dato != -1)
    {
    Serial.println(dato);
//    delay(100);
    }
   }
   








   //Leer los valores del Acelerometro de la IMU
   Wire.beginTransmission(MPU);
   Wire.write(0x3B); //Pedir el registro 0x3B - corresponde al AcX
   Wire.endTransmission(false);
   Wire.requestFrom(MPU,6,true); //A partir del 0x3B, se piden 6 registros
   AcX=Wire.read()<<8|Wire.read(); //Cada valor ocupa 2 registros
   AcY=Wire.read()<<8|Wire.read();
   AcZ=Wire.read()<<8|Wire.read();
 
    //Se calculan los angulos Y, X respectivamente.
   Acc[1] = atan(-1*(AcX/A_R)/sqrt(pow((AcY/A_R),2) + pow((AcZ/A_R),2)))*RAD_TO_DEG;
   Acc[0] = atan((AcY/A_R)/sqrt(pow((AcX/A_R),2) + pow((AcZ/A_R),2)))*RAD_TO_DEG;
 
   //Leer los valores del Giroscopio
   Wire.beginTransmission(MPU);
   Wire.write(0x43);
   Wire.endTransmission(false);
   Wire.requestFrom(MPU,4,true); //A diferencia del Acelerometro, solo se piden 4 registros
   GyX=Wire.read()<<8|Wire.read();
   GyY=Wire.read()<<8|Wire.read();
 
   //Calculo del angulo del Giroscopio
   Gy[0] = GyX/G_R;
   Gy[1] = GyY/G_R;
 
   //Aplicar el Filtro Complementario
   Angle[0] = 0.98 *(Angle[0]+Gy[0]*0.010) + 0.02*Acc[0];
   Angle[1] = 0.98 *(Angle[1]+Gy[1]*0.010) + 0.02*Acc[1];
 
   //Mostrar los valores por consola
//   Serial.print("Angle X: "); Serial.print(Angle[0]); Serial.print("\n");
//   Serial.print("Angle Y: "); Serial.print(Angle[1]); Serial.print("\n------------\n");

// indicamos la velocidad de los motores angulo Z   
//vel1 existe porque entra dos veces al bucle
  if(Serial.available() > 0)
  {
    vel1 = Serial.parseInt(); //Leer un entero por serial
    Serial.print(vel);
    if(vel1 != 0)
    {
      vel=vel1;
// calculamos la media de los valores i j k l       
      media=(i+j+k+l)/4;
// medimos cual es la "aceleracion" para calcular la diferencia entre la velociad deseada y los valores actuales
      aceleracion=vel-media;
      l=l+aceleracion; 
      i=i+aceleracion;
      j=j+aceleracion;
      k=k+aceleracion;
      
     
       Serial.print("dando velocidad ");
    }
  }
  delay(10); //Nuestra dt sera, pues, 0.010, que es el intervalo de tiempo en cada medida




// Estabilidad angulo X
    if( Angle[0]-a>2.5)
      {
        i++,j++,k--,l--;
        Serial.print("Angle X+ ");Serial.print("\n");
        
      }
    if( Angle[0]-a<-2.5)
      {
        i--,j--,k++,l++;
        Serial.print("Angle X- ");Serial.print("\n");
        
      }   
//    if( Angle[0]-a>10)
//      {
//        i=i+5,j=j+5,k=k-10,l=l-10;
//      }
//    if( Angle[0]-a<-10)
//      {
//        i=i-10,j=j-10,k=k+10,l=l+10;
//      }   
//    if( Angle[0]-0>20)
//      {
//         i=i+10,j=j+10,k=k-10,l=l-10;
//         Serial.print("Angle X+20 ");Serial.print("\n");
//      }
//    if( Angle[0]-0<-20)
//      {
//        i=i-10,j=j-10,k=k+10,l=l+10;
//        Serial.print("Angle X-20 ");Serial.print("\n");
//      }   


// Estabilidad angulo y        
    if( Angle[1]-b > 2.5)
      {
        i++,j--,k++,l--;
        Serial.print("Angle Y+ ");Serial.print("\n");
      }
    if( Angle[1]-b < -2.5)
      {
        i--,j++,k--,l++;
        Serial.print("Angle Y- ");Serial.print("\n");
      }
//   if( Angle[1]-a>10)
//      {
//        i=i+10,j=j-10,k=k+10,l=l-10;
//      }
//    if( Angle[1]-a<-10)
//      {
//        i=i-10,j=j+10,k=k-10,l=l+10;
//      }   
//    if( Angle[1]-0>20)
//      {
//        i=i+10,j=j-10,k=k+10,l=l-10;
//        Serial.print("Angle Y+20 ");Serial.print("\n");
//      }
//    if( Angle[1]-0<-20)
//      {
//        i=i-10,j=j+10,k=k-10,l=l+10;
//        Serial.print("Angle Y-20 ");Serial.print("\n");
//      }



// marcar maximos y minimos
         
if( i>1500)
{i=1500;
  }
if (i<1000)
{i=1000;
  }

if( j>1500)
{j=1500;
  }
if (j<1000)
{j=1000;
  }

if( k>1500)
{k=1500;
  }
if (k<1000)
{k=1000;
  }
  
if( l>1500)
{l=1500;
  }
if (l<1000)
{l=1000;
  }


if( Angle[0]-a<2.5 && Angle[0]-a>-2.5&&  Angle[1]-b<2.5 &&  Angle[1]-b>-2.5)
{
  i=vel;
  j=vel;
  k=vel;
  l=vel;
   Serial.print("estabilizado");
  }
  
motor1.writeMicroseconds(i);      
motor2.writeMicroseconds(j);
motor3.writeMicroseconds(k);
motor4.writeMicroseconds(l);
}

maybe the code is not optimized as much as possible, but it works, and the problem is bluetooth

Thanks for the help

My guess is, that the pwm-signal is interrupted by the SoftwareSerial-Port.
Try using the hardware serial port (0, 1) instead. It's inconvenient, I know, but worth a try.

lg, couka

thank you very much, indeed, have made me happy.

Really you do not get the idea of how grateful I am.

If you could do me one last favor, since you knew what the problem was, can u explain me what was the problem? because in truth I can't understand why the arduino fail when I use the other pins with the SoftwareSerial.

Now I have to always be connected to pins 0 and 1 or there is some other solution?

Ty for real.

VenatorV:
thank you very much, indeed, have made me happy.

Really you do not get the idea of how grateful I am.

I'm happy to hear that :slight_smile:

Unfortunately I can't explain exactly what's going wrong. The arduino software keeps us away from internal stuff most of the time and sometimes that hides problems. You could try other combinations of pins, maybe you are lucky an find some that don't interfere with the Servo library.

If not, you can use another arduino board which has more than one hardware serial port, for example the arduino mega, due or zero.

lg, couka