passing one no. and getting many no.

Hi everyone I am getting the problem that giving one no. from the app and getting 3 no. in Arduino\
I am using the below code can someone tell the solution for that
And I am using the code blocks of MIT app inventor site image is attached below
I had added a joystick whose value range is from x=0,y=0 to x=200,y=200 and a slider which gives values from 255 to 335 that's why the buttons are returning values like 341,342
Now if I press the button the value to be sent is 341 or like that but in Arduino Uno, I am getting 58,0,0 something like that. I am using an HC05 Bluetooth module to transfer this data

#include <SoftwareSerial.h>

SoftwareSerial bluetooth(A5,A4);

void setup() 
{
   Serial.begin(9600);
   bluetooth.begin(9600);
   pinMode(A5,INPUT);
   pinMode(A4,OUTPUT);
}

void loop() 
{
  if( bluetooth.available()>0 )
   {
     int value = bluetooth.read();
     Serial.println(value);
   }
}

Annotation 2020-09-01 205041.png

read() function reads a single character and returns the ASCII code for it.

"341" therefore results in 3 values:
51 = '3'
52 = '4'
49 = '1'

Have a read of Serial Input Basics.

Thanks, Buddy but now how I can make it getting right values

int value = bluetooth.parseInt();

it's not working bro I am getting only 0 for every button in Arduino

Please post your updated sketch in a new post.

This is the code I am using

#include <SoftwareSerial.h>

SoftwareSerial bluetooth(A5,A4);

void setup() 
{
   Serial.begin(9600);
   bluetooth.begin(9600);
   pinMode(A5,INPUT);
   pinMode(A4,OUTPUT);
}

void loop() 
{
  if( bluetooth.available()>0 )
   {
     int value = bluetooth.parseInt();
     Serial.println(value);
   }
}

Can someone write me a code for reading the number like 500 as a whole that I passed from Bluetooth app
I had written a code mentioned below but when I pass number from Bluetooth it gives me a 0.

#include <SoftwareSerial.h>

SoftwareSerial bluetooth(A5,A4);

void setup() 
{
   Serial.begin(9600);
   bluetooth.begin(9600);
   pinMode(A5,INPUT);
   pinMode(A4,OUTPUT);
}

void loop() 
{
  if( bluetooth.available()>0 )
   {
     int value = bluetooth.parseInt();
     Serial.println(value);
   }
}

Topics with duplicate content merged

Why did you start a new topic ?
All it does is waste time and put members off answering

Can someone write me a code for reading the number like 500 as a whole that I passed from Bluetooth app
I had written a code mentioned below but when I pass number from Bluetooth it gives me a 0.

The code you posted works correctly in a test I just ran using Kai Morich's Serial Bluetooth Terminal.

And I am using the code blocks of MIT app inventor

It is better to develop your program using an existing widely used terminal app rather than something you have written.

You may also want to take a look at this thread
https://forum.arduino.cc/index.php?topic=173246.0

I suggest you go back to your previous code which prints out the ASCII values you are receiving and tell us EXACTLY what output you get in the serial monitor, instead of using vague descriptions such as...

values like 341,342

My guess is the data you are send/receiving is not formatted correctly as ASCII.

Thanks for your support @pcbbc and sorry for that @UKHeliBob
I am attaching some pics which will tell you the output which I am getting in the serial monitor and what I am passing through the app and I am providing the previous code that I was using back then.

  #include <SoftwareSerial.h>

  SoftwareSerial bluetooth(A5,A4);

  void setup()
  {
   Serial.begin(9600);
   bluetooth.begin(9600);
   pinMode(A5,INPUT);
   pinMode(A4,OUTPUT);
  }

  void loop()
  {
  if( bluetooth.available()>0 )
   {
     int value = bluetooth.read();
     Serial.println(value);
   }
  }

344 = 1 * 256 + 88

int lo = bluetooth.read();
int hi = bluetooth.read();
int value = hi * 256 + lo;

Edit: This is an exceedingly bad way of sending numbers over a serial link. If the receiver gets out of step with the sender (some data is missing) you could end up reading the hi byte of one value and the low byte of the next and combine them into a garbage value.

1- Make sure that in your Java code you are sending a String not an int. For example your Java code should be send("341") and not send(341).

2- Are you sure your hc-05 baud rate is 9600? Connect it to a USB-TTL module and see if you can read data from it at 9600 baud.