@Override
            public boolean handleMessage(Message msg) {
              switch (msg.what) {
                case Bluetooth.MESSAGE_STATE_CHANGE:
                  Log.d(TAG, "MESSAGE_STATE_CHANGE: " + msg.arg1);
                  break;
                case Bluetooth.MESSAGE_WRITE:
                  Log.d(TAG, "MESSAGE_WRITE ");
                  break;
                case Bluetooth.MESSAGE_READ:
                  byte[] readBuf = (byte[]) msg.obj;
                  String strIncom = new String(readBuf, 0, msg.arg1);
                  sb.append(strIncom);
                  int endOfLineIndex = sb.indexOf("\r\n"); // determine the end-of-line
                  if (endOfLineIndex > 0) { // if end-of-line,
                    String sbprint = sb.substring(0, endOfLineIndex); // extract string
                    sb.delete(0, sb.length()); // and clear

                    Log.d("READ_FROM_ARDUINO", sbprint + "");
                    try {

                      distanceToObstacle =
                          Utilities.normalizeReadingsFromDistanceSensor(
                              Integer.parseInt(sbprint), distanceToObstacle);

                      Log.d("READ_FROM_ARDUINO_NORM", distanceToObstacle + "");
                      tvDistance.setText(distanceToObstacle + "cm");
                      if (distanceToObstacle < 40 && !(command.equals("STOP"))) {
                        Utilities.setDirectionImage("STOP", ivDirection, bt);
                        textToSpeech.speak(
                            "YOU ARE ABOUT TO HIT AN OBSTACLE STOPPING",
                            TextToSpeech.QUEUE_FLUSH,
                            null);
                        ((TextView) findViewById(R.id.tvResults)).setText("STOP");
                        command = "STOP";
                      }
                      // distanceToObstacle = Integer.parseInt(sbprint);
                    } catch (Exception e) {
                      e.printStackTrace();
                      Log.e(TAG, "handleMessage: CRASH CONVERSION");
                    }
                  }
                  break;
                case Bluetooth.MESSAGE_DEVICE_NAME:
                  Log.d(TAG, "MESSAGE_DEVICE_NAME " + msg);
                  break;
                case Bluetooth.MESSAGE_TOAST:
                  Log.d(TAG, "MESSAGE_TOAST " + msg);
                  break;
              }
              return false;
            }