How to return the value in Arduino function (that can be read by the connected device)?
You are using the USB interface, right? So you just use Serial to send data back. For example, this would send the distance every second:

unsigned long lastSent;
void loop() {
  distance = Dist.getDistanceCentimeter();
  if (millis () - lastSent &gt;= 1000)  // every second
  {
    lastSent = millis ();
    Serial.println (distance);
  }

  if (distance &lt;= 5 &amp; distance &gt; 1)
  {
    if (Serial.available()) {
      command = Serial.read();
      switch (command) {
        case 'a':
          forward();
          servoX.write(90);
          command = 0;
          break;
      }  // end of switch
    }
  }
}