Cannot send string values one by one to Arduino from a Bluetooth Android app

I am working on a project where I pass string one by one to Arduino from my android app using Bluetooth. The following is my java code.I send string values to this function one by one.The problem here is I receive only one value in the Arduino serial monitor.The remaining values are not received.

public static  void getDistance(float x){
    String xMoved = Float.toString(x);

    Log.d(TAG, "getDistance: called");
    try {

    } catch (IOException e) {
        Log.d(TAG, "getDistance: "+e);
    finally {
        Log.d(TAG, "getDistance:"+"try catch successful");

The following is the the code in my arduino:

/* Example sketch to control a 28BYJ-48 stepper motor with ULN2003 driver board and Arduino UNO. More info: */
// Include the Arduino Stepper.h library:
#include <Stepper.h>
// Define number of steps per rotation:
const int stepsPerRevolution = 2048;
// Wiring:
// Pin 8 to IN1 on the ULN2003 driver
// Pin 9 to IN2 on the ULN2003 driver
// Pin 10 to IN3 on the ULN2003 driver
// Pin 11 to IN4 on the ULN2003 driver
// Create stepper object called 'myStepper', note the pin order:
int  state;
String command;
Stepper myStepper = Stepper(stepsPerRevolution,2,4,3,5);
void setup() {
  // Set the speed to 5 rpm:

  // Begin Serial communication at a baud rate of 9600:
void loop() {


    command = Serial.readStringUntil('\n');
    state = command.toInt();



The following is my logcat:

Please find my attachment image

I am confused what am I doing wrong?Anybody please help me out with this.


I am guessing that the part of the picture that is missing here is that in order to receive data via BlueTooth from the the Android app you have a BlueTooth board such as a HC05 or HC06 connected to your Uno? Furthermore, looking at your Uno code snippet it would appear that this would have to be connected to the RXD0/TXD0 pins?

The Uno has only one UART which is used by USB to communicate with the on-board MCU. The running of the MCU can be suspended so that the RXD0/TXD0 can be used for USB-to-Serial type applications, but serial is a 1:1 technology that was not designed for communications between multiple devices simultaneously. Your BT board will be competing with USB for communication with the MCU and the result will be unpredictable. In your sketch "if(Serial.available())" is presumably waiting for serial data from BlueTooth, while "Serial.println(state);" is intended to push the same data out to USB? One operation will interfere with and block the other.

Since you are using a UNO, I would suggest using SoftwareSerial to connect the BlueTooth board. SoftwareSerial emulates a serial port using ordinary GPIO pins and you can choose which two pins to use. This will allow you to communicate with both BlueTooth and USB separately and pass information between them while avoiding such complications. Bear in mind that if you later want to increase the speed of your serial communication, the baudrate for SoftwareSerial is limited to no more than 57600 baud (some say 38400) whereas your hardware serial port can be pushed to 115200.