Control BT Arduino-Android dont work with usb conect

Hi friends good afternoon, I am writing to see if you can help me with a little problem that I have and that brings me to head the truth. I have a bluetooth shield Seeedstudio and my mobile android establish a one-way communication to control a relay board.

The tick of the matter is that when I have the arduino connected to the PC via USB works perfectly, but when I have it connected to a battery ... but it connects and other characters that happened, it does na ... what I want xD I attached the code if you can see something that escapes me. greetings and thanks in advance.

the code is the followin:

#include <SoftwareSerial.h> //Software Serial Port

#define RxD 7
#define TxD 6

#define PINLEDON 12
#define PINLEDOFF 13
#define PINBUZZ 0

#define LEDON() {digitalWrite(PINLEDON, HIGH);digitalWrite(PINLEDOFF, LOW);}
#define LEDOFF() {digitalWrite(PINLEDOFF, HIGH);digitalWrite(PINLEDON, LOW);}
#define ALLLED() {digitalWrite(PINLEDON, LOW);digitalWrite(PINLEDOFF, LOW);}
#define BUZZ() {analogWrite(PINBUZZ, 255);delay(1000);analogWrite(PINBUZZ, 0);}
#define REPEATLEDON() {digitalWrite(PINLEDOFF, LOW);digitalWrite(PINLEDON, HIGH);delay(150);digitalWrite(PINLEDON, LOW);delay(150);}

#define DEBUG_ENABLED 1

SoftwareSerial blueToothSerial(RxD,TxD);

void setup()
{

LEDOFF();
Serial.begin(9600);
pinMode(RxD, INPUT);
pinMode(TxD, OUTPUT);
pinMode(PINLEDON, OUTPUT);
pinMode(PINLEDOFF, OUTPUT);
pinMode(PINBUZZ, OUTPUT);
delay(2000);
setupBlueToothConnection();
LEDON();
delay(2000);
ALLLED ();
BUZZ()
}

void loop()
{
char recvChar;

while(1)
{

if(blueToothSerial.available())
{

recvChar = blueToothSerial.read();
Serial.print(recvChar);

if(recvChar == 'a')
{
LEDON();
}
else if(recvChar == 'b')
{
LEDOFF();
}
}
}
}

void setupBlueToothConnection()
{
blueToothSerial.begin(38400); //38400 // Set BluetoothBee BaudRate to default baud rate 38400
blueToothSerial.print("\r\n+STWMOD=0\r\n"); // set the bluetooth work in slave mode
blueToothSerial.print("\r\n+STNA=BT\r\n"); // set the bluetooth name as "SeeedBTSlave"
blueToothSerial.print("\r\n+STOAUT=1\r\n"); // Permit Paired device to connect me
blueToothSerial.print("\r\n +STPIN=0000\r\n"); // pin
blueToothSerial.print("\r\n+STAUTO=0\r\n"); // Auto-connection should be forbidden here
delay(2000); + // This delay is required.
blueToothSerial.print("\r\n+INQ=1\r\n"); // make the slave bluetooth inquirable
Serial.println("The slave bluetooth is inquirable!");
delay(2000); // This delay is required.
blueToothSerial.flush();
}

jlazaro:
when I have the arduino connected to the PC via USB works perfectly, but when I have it connected to a battery ...

It depends on the battery, but it could be a power problem.

Nick_Pyne thank you very much, is a power problem, I have now used four batteries 1.5V serial, and it works correctly.
have a good day. :smiley:

It might not work correctly for very long. It may be that you don't need to run it very long but, if you do, note that the top limit of the batteries is about 6v and that is the bottom practical limit for Arduino. Therefore 5x1.5 is probably a better bet.