My arduino code works for a while, then just shows 0,1 in the serial. I am getting information from the Bluetooth serial, and adding 1 each time to move servo motors of an arm. The app sends for a while, and the tx light is lit. After about 15 secs, it just stops. I don't know if this is a hardware or software problem. On my android phone, it gets a "broken pipe warning." Anyone have suggestions?
#include <Servo.h>
String readString;
Servo myservo;
Servo myservo2;
Servo myservo3;
Servo myservo4;
Servo myservo5;
int x1;
int y1;
int z1;
int p1;
int stringy;
int stringz;
String p;
String x;
String y;
String z;
int pos1 = 0;
int pos2 = 0;
int pos3 = 0;
int buttonup = 0;
int buttondown = 0;
int buttonleft = 0;
int buttonright = 0;
int openclosed = 0;
void setup()
{
pinMode(0, OUTPUT);
pinMode(1, INPUT);
myservo.attach(2);
myservo2.attach(3);
myservo3.attach(4);
myservo4.attach(5);
myservo5.attach(6);
Serial.begin(9600);
myservo.write(0);
myservo2.write(0);
myservo3.write(0);
myservo4.write(0);
myservo5.write(0);
}
void loop()
{
if (buttonup == 1){/*Up button*/
if (pos1 != 180){
pos1++;
myservo.write(pos1);
myservo2.write(pos1);
Serial.print("Pos1:");
Serial.println(pos1);
delayMicroseconds(1000);
}
}
if (buttondown == 1){/*Down Button*/
if (pos1 != 0){
pos1= pos1 -1;
myservo.write(pos1);
myservo2.write(pos1);
Serial.print("Pos1:");
Serial.println(pos1);
delayMicroseconds(1000);
}
}
if(buttonleft == 1){/*Left button*/
if(pos2 != 0){
pos2 = pos2 - 1;
myservo3.write(pos2);
Serial.print("Pos2:");
Serial.println(pos2);
delayMicroseconds(1000);
}
}
if (buttonright == 1){/*Right button*/
if (pos2 != 180){
pos2++;
myservo3.write(pos2);
Serial.print("Pos2:");
Serial.println(pos2);
delayMicroseconds(1000);
}
}
if (Serial.available() > 0){
char c = Serial.read();
Serial.print(c);
if (c == '1'){/*Up Button*/
buttonup++;
}
if(c == '2'){
buttonup = buttonup-1;
}
if(c == '3'){/*down button*/
buttondown++;
}
if(c == '4'){
buttondown = buttondown -1;
}
if(c == '5'){/*Left button*/
buttonleft++;
}
if(c == '6'){
buttonleft = buttonleft - 1;
}
if(c == '7'){/*right button*/
buttonright++;
}
if(c == '8'){
buttonright = buttonright-1;
}
if(c == '0'){
Serial.println("Open");
myservo5.write(180);
}
if(c == '9'){
Serial.println("Closed");
myservo5.write(0);
}
}
}