How to control servo motor with Bluetooth

I am working on project controlling arduino servo with App Inventor bluetooth app
i set slider minvalue to 0 and maxvalue to 180 in app inventor
when i open my serial monitor and move slider to 180 then i receive value of 255 in serial monitor and for any other value 0-179 i receive 254 and servo is not moving

#include <SoftwareSerial.h> // TX RX software library for bluetooth
#include <Servo.h> // servo library
Servo myservo; // servo name
int bluetoothTx = 10; // bluetooth tx to 10 pin
int bluetoothRx = 11; // bluetooth rx to 11 pin
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);
void setup()
{
myservo.attach(9); // attach servo signal wire to pin 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()> 0 ) // receive number from bluetooth
{
int servopos = bluetooth.read();// save the received number to servopos
myservo.write(servopos);
Serial.println(servopos); // serial print servopos current number received from bluetooth
}
}

//code ends here

Does you program work if you change it so you can send data from the Serial Monitor?

My wild guess is that when the value is (say) 150 your AppInventor program is sending the characters 1,5,0 and a carriage-return. If it does use that format it is sending 4 characters but your program is only reading one of them.

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data. There is also a parse example to illustrate how to extract numbers from the received text.

...R

I am using send1bytenumber method in blutooth call in app inventor and these value will be 0-255
When i send 180 value serial monitor shows 255 and for any other value less than 180 serial monitor shows 254

davidkhan:
I am using send1bytenumber method in blutooth call in app inventor and these value will be 0-255
When i send 180 value serial monitor shows 255 and for any other value less than 180 serial monitor shows 254

Do you have the option to send the number as text?

It will make debugging much easier.

...R