Problem with sending numbers via bluetooth

Hello,

I am making a project to control servo motors by bluetooth. So I'm using an Arduino UNO, a bluetooth HC-05 module and an application developed in the MIT app inventor. I have 3 servo motors, when sending values smaller than 127 it does okay, however for values greater than 128 on the serial monitor, it shows negative values. For example, when I send 135 it gets -121. In the MIT inventor app I am already sending the data with 2 Bytes and the variable that receives them is of type int. In the annex, I show the part of the blocks that I used in MIT.What do you suggest I do?

Image from Original Post so we don't have to download it. See this Image Guide

...R

It sounds as if you may be forcing a byte (unsigned) value into a char - which is a signed variable.

But as you have not posted your Arduino code that is just a wild guess.

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data.

...R

#include<SoftwareSerial.h>
#include<Servo.h>


Servo myservo1;
Servo myservo2;
Servo myservo3;

int bluetoothTx = 10;
int bluetoothRx = 11;
int recebido = 0;
int num;
String device;
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);

void setup()

{

myservo1.attach(3);
myservo2.attach(5);
myservo3.attach(6);

//Setup usb serial connection to computer

Serial.begin(9600);

//Setup Bluetooth serial connection to android

bluetooth.begin(9600);

}

void loop()

{

    while (bluetooth.available())       //Check if there is an available byte to read
  {
    delay(10);                        //Delay added to make thing stable 
    char c = bluetooth.read();       //Conduct a serial read
    device += c;                    //build the string.
  }

    if (device.length() > 0) 
  {
    Serial.println(device); 

   char motor = device[0]; 
   int angulo = device[2]; 
   Serial.print(" "); 
   Serial.println(angulo); 
   Serial.println(motor); 
   if ( motor == 'a') 
   { 
          Serial.println(angulo);
          Serial.print("angulo1");
          myservo1.write(angulo); 
   } 
   if ( motor == 'b') 
   { 
          Serial.println(angulo);
          Serial.print("angulo2");
          myservo2.write(angulo); 
   } 
   if ( motor == 'c') 
   { 

          Serial.println(angulo);
          Serial.print("angulo3");
          myservo3.write(angulo); 
   } 
   
   device=""; //Reset the variable
   } 
}

You are not using the String object correctly, but Strings should not be used at all with Arduino, because they cause memory problems.

Study the link in reply#2.