Bluetooth doesnt work

when i connect my bluetooth via my pc the bluetooth receives and transmits fine, but when connected to my external power up(5v) it gets connected but neither does the tx led light up or receive anything.

I think it's a hardware problem and has nothing to do with AppInventor. We do help with the Arduino code sometimes, but hardware issues with the power supply must be resolved on the Arduino forums.

i dont think its an power issue, but maybe you could confirm it?

#include <SoftwareSerial.h>

#include <Servo.h>
Servo myservo1, myservo2, myservo3;

int bluetoothTx = 0;
int bluetoothRx = 1;

SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);

void setup()
{
myservo1.attach(9);
myservo2.attach(10);
myservo3.attach(11);
//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 bluetooth works when powered from usb, but not when connected to external power, there is a hardware problem.

I took a closer look at your code. I see you are using pins 0 and 1 for SoftwareSerial bluetooth. This is incorrect because pins 0 and 1 are reserved for Hardware Serial to be connected via USB. Change pins 0 and 1 in the code to other free pins, e.g. 2 and 3. Connect the bt hc05 module to pins 2 and 3.

#include <SoftwareSerial.h>

#include <Servo.h>
Servo myservo1, myservo2, myservo3;

int bluetoothTx = 2;
int bluetoothRx = 3;

SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);

void setup()
{
myservo1.attach(9);
myservo2.attach(10);
myservo3.attach(11);
//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);
}

}

}
1 Like