My arduino code works for a while, then just shows 0,1 in the serial.

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);
    }
  
    
  }

 
}

That code looks okey. Show us the sequence sent to the controller and the data read back to Serial monitor.

I'm just curious, as I did not see any BT libraries or BT settings or BT code used, which MCU do you have?

Because if you are getting a broken pipe error then it would be best to look into the BT code thing do, no?

Basically, the sequence sent is just 1,2,3,4,5 or 6. Then it just keeps adding and adding or subtracting. Then 1 of 2 things would happen, the tx light on my uno would freeze flash and it would just alternate between 0,1 or 179,180 or it would show a broken pipe error. As for the Bluetooth, I'm just using an HC-05 in the TX, RX ports so I didn't think to put Bluetooth libraries. Should I try Bluetooth libraries?

  pinMode(0, OUTPUT);
  pinMode(1, INPUT);
....
  Serial.begin(9600);

  }

Err.

Too much code.

ALso, note @TheMemberFormerlyKnownAsAWOL's hint.

What one doesn't know often doesn't hurt it says, but not in this matter...

Idahowalker:
ALso, note @TheMemberFormerlyKnownAsAWOL's hint.

Both of them

The way your servos are wired may. E significant , the HC05 takes a surge in current when transmitting too .

Hi,

Please read the post at the start of any forum , entitled "How to use this Forum".
OR
http://forum.arduino.cc/index.php/topic,148850.0.html.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

How are you powering your project?
What model Arduino are you using?

The hint is pointing to the fact that you are using pin0 and pin1 of the controller, these are to be avoided as they are the programming and serial monitor comms pins.

Tom... :slight_smile: