HELP! 516: Broken pipe

Hey Yall!
I'm pretty new to Arduino, and just got myself mixed in with programming due to a science fair project that required programing knowledge. Essentially, my project consist of using a Arduino and hc-05 to control 4 servo motors with a custom made app. I followed a tutorial and am starting to learn how the code works. However, when using an external power source like a battery pack, I get the error 516: Broken Pipe. When I connect it to my computer however, It runs fine. What do I do?
Code:

#include <SoftwareSerial.h> // TX RX software library for bluetooth
#include <Servo.h> // servo library 
Servo myservo1, myservo2, myservo3, myservo4; // servo name
int bluetoothTx = 10; // bluetooth tx to 10 pin
int bluetoothRx = 11; // bluetooth rx to 11 pin
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);
void setup()
{
  myservo1.attach(3); // attach servo signal wire to pin 9
  myservo2.attach(5);
  myservo3.attach(6);
  myservo4.attach(9);
  //Setup usb serial connection to computer
  Serial.begin(9600);
  //Setup Bluetooth serial connection to android
  bluetooth.begin(9600);
}
void loop()
{
  //Read from bluetooth and write to usb serial
  if(bluetooth.available()>= 2 )
  {
    unsigned int servopos = bluetooth.read();
    unsigned int servopos1 = bluetooth.read();
    unsigned int realservo = (servopos1 *256) + servopos;
    Serial.println(realservo);
    if (realservo >= 1000 && realservo <1180) {
      int servo1 = realservo;
      servo1 = map(servo1, 1000, 1180, 0, 180);
      myservo1.write(servo1);
      Serial.println("Servo 1 ON");
      delay(10);
    }
    if (realservo >= 2000 && realservo <2180) {
      int servo2 = realservo;
      servo2 = map(servo2, 2000, 2180, 0, 180);
      myservo2.write(servo2);
      Serial.println("Servo 2 ON");
      delay(10);
    }
    if (realservo >= 3000 && realservo <3180) {
      int servo3 = realservo;
      servo3 = map(servo3, 3000, 3180, 0, 180);
      myservo3.write(servo3);
      Serial.println("Servo 3 ON");
      delay(10);
    }
    if (realservo >= 4000 && realservo <4180) {
      int servo4 = realservo;
      servo4 = map(servo4, 4000, 4180, 0, 180);
      myservo4.write(servo4);
      Serial.println("Servo 4 ON");
      delay(10);
    }
  }
}

Im not sure what to do. I'm guessing that it has to do with Serial.Begin(9600), as I do not have a computer connected. If that's the problem, how do I fix this using an external battery?
Thanks

I assume that the custom app is running on a smartphone and that the app is using Bluetooth. Is the 'phone pairing OK with the HC05 ?

Yeah, essentially when I use my computer as a power source It works fine, and the error does not pop up. It is when I use battery power that this error occurs. And yes, the servos are controlled via an app on my smart phone.

It is when I use battery power that this error occurs.

What type of battery are you using ?
Is it a 9V PP3 by any chance ?

How is it connected to the Arduino ?

I get the error 516: Broken Pipe.

Which device produces that error ?

The phone itself

yes it is a 9V PP3. It is connected by a battery clip attached to the arduino port

Then it quite probably cannot provide enough current to power your project. Those batteries are only really suited to low current applications such as smoke detectors.

What is the voltage of the PP3 when connected to the project ?

Try using 6 AA batteries in series instead

I'm not 100% sure, but the hc-05 is connected to the 5v pin

In this case it is the battery voltage that you need to look at first

An alternative test would be to use a fresh PP3 battery to see whether the project works when using that but even if it does then it will not last ling. You need an alternative power supply. Have you got a 5V "wall wart" that you could try, for instance ?

I have tried multiple samples of the same battery, and it did not work. The problem with a "wall wart" is that it needs to be plugged to the wall, which cannot work since the servos and Arduino have to be inside a tube.

Have you got a way of measuring the battery voltage ?

No, I do not

My money is still on the fact that a PP3 cannot supply the required current

Exactly what hardware is being used in the project ?

An Arduino-Uno, Hc-05 Bluetooth model, Generic Jumper wires, a breadboard, 4Pcs SG90 9g Micro Servos, and a battery port.

The servos use about 10 mA each when idle, about 200 mA each when running and about 600 mA each when stalled. That is way too much current for the 5V regulator on the Uno to supply safely. In addition to that a PP3 battery has a capacity of about 550 mAh so is not capable of supplying the required current for very long

The servos should not be powered directly from the Uno 5V pin and a PP3 battery is not a suitable power supply for your project anyway

If the Uno and servos are going to be in a tube then the tube must be quite large. I suggest that you power your project from AA batteries and power the servos directly from them and not via the Arduino

Now would be a good time to get a digital multimeter. Even the cheapest DMM from Ebay will be good enough to measure simple currents and voltages

Nevermind! I have fixed the problem, it was due to the innsuficent power coming from the power source, thanks for the help!

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.