title: Receive sensor values from bluetooth hc05 to Android
body: <p>I'm sending sensor values from Arduino via an HC-05 Bluetooth module to Android. I'm receiving the values but they are not showing properly in my textviews.</p>
  
  <p>I'm using 2 sensors and their values are like this (example first sensor = 120, 97, 110 etc)</p>
  
  <p>Sensor2 values are like this (97, 96, 100 etc)
  i.e values are changing.</p>
  
  <p>Now my Android code is:</p>
  
  <pre><code>if (msg.what == handlerState) {
    //if message is what we want
    String readMessage = (String) msg.obj;
    // msg.arg1 = bytes from connect thread
    recDataString.append(readMessage);
    //keep appending to string until ~
    int endOfLineIndex = recDataString.indexOf("~");
    // determine the end-of-line
    if (endOfLineIndex &gt; 0) {
      // make sure there data before ~
      String dataInPrint = recDataString.substring(0, endOfLineIndex);
      // extract string
      if (recDataString.charAt(0) == '#') {
        //if it starts with # we know it is what we are looking for
        String sensor0 = recDataString.substring(1, 3);
        //get sensor value from string between indices 1-5
        String sensor1 = recDataString.substring(4, 6);
        //same again...
        heart_rate.setText(sensor0);
        // update the textviews with sensor values
        temperature.setText(sensor1);
      }
      recDataString.delete(0, recDataString.length());
      //clear all string data
      dataInPrint = " ";
    }
  }
  </code></pre>
  
  <p>When I receive 2-digit data on sensor 1 like this (76) and 2-digit data also on sensor 2 (97) it shows the data properly. But if values are greater than 3 digits the values don't show up properly and some digits of the first textview appear on the second textview. I think the problem is getting the data between the indices. How can I manage this? Please help me.</p>
  
  <p>Sorry for my bad English, I'm not a native speaker.</p>