Troubles with Bluetooth connection

English is not my first languaje so sry for grammar mistakes
Hi, i'm working in a communication between arduino and appinventor using bluetooth, and i'm having some difficulties. When I sent for the first time some data from the app to the arduino all seems to work propperly, but the second time the app closes displaying a "the app doesn't answer'' text or the app shows a ''error 516: broken pipe'' warning.
This is the arduino code:

#include <Servo.h>
#include <SoftwareSerial.h>

Servo servoMotor;
Servo servoMotor2;
SoftwareSerial BT(10,11);

int Sensor = digitalRead(A1);
int Puerta1=4;
int Puerta2=7;
char data='d';

void setup() {
BT.begin(9600);
Serial.begin(9600);
servoMotor.attach(6);
servoMotor2.attach(5);
servoMotor.write(0);
servoMotor2.write(0);
}

void loop()
{
if (Serial.available() > 0)
{
data = Serial.read();
Serial.println(data);
if (data=='P')
{
servoMotor.write(45);
servoMotor2.write(45);
digitalWrite(Puerta1,HIGH);
delay (10000);
digitalWrite(Puerta1,LOW);
}
if (data=='L')
{
servoMotor.write(0);
servoMotor2.write(0);
digitalWrite(Puerta1,HIGH);
delay (10000);
digitalWrite(Puerta1,LOW);
}
if (data=='V')
{
servoMotor.write(135);
servoMotor2.write(135);
digitalWrite(Puerta1,HIGH);
delay (10000);
digitalWrite(Puerta1,LOW);
}
}
if(Sensor==HIGH)
{
BT.println(1);
Serial.println(1);
digitalWrite(Puerta2,HIGH);
delay (5000);
digitalWrite(Puerta2,LOW);
}
}

And this is the app code (2 different screens with the same problem):


If someone can help me i will be very gratefull ^^

Have you searched :mag: the community for error 516 broken pipe ?

Maybe error is caused by power failure in servo motor ?

Hi, thx for the reply
Yes, I have seen this post before writing mine, but i have the servos put in a diferent power supply since the beggining, so i'm pretty sure this isn't the issue here

1 Like