Char String Conversion using String() function

#include <SoftwareSerial.h>
#include <SPI.h>                             // Serial Peripheral Interface Library
#include <String.h>                          

// defines pins numbers
const int trigPin = 8;
const int echoPin = 9;
const int Rx = 10;
const int Tx = 11;

// defines variables
byte size;
long duration;
int distance;
int INPUT_SIZE = 30;

// Others
SoftwareSerial Bluetooth (Rx,Tx);
 
//Main Functions

void setup() {
pinMode(Rx, INPUT);
pinMode(Tx, OUTPUT);
Bluetooth.begin(9600);
Bluetooth.setTimeout(1000);                  // 1000 ms time out
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
Serial.begin(9600); // Starts the serial communication
Bluetooth.println ("Hello , please send \"Distance\" to veiw the distance! Thank you ");

}

void loop() 
{
bluetooth_func();

}

//Minor functions
void bluetooth_func()
{
  
  if (Bluetooth.available()>0)
  {
   char input[INPUT_SIZE + 1];
   size = Bluetooth.readBytesUntil('\n', input, INPUT_SIZE);
   input[size] = '\0';
   compare(input);
  }
    delayMicroseconds(2000);
  }

  
void compare(char* A)
{
String comparator= String (A);
if (comparator.equalsIgnoreCase("Distance"))
{Bluetooth.print("The distance between the sensor and the object is ");
Bluetooth.println(find_distance());}
else if (comparator.equalsIgnoreCase("name"))
Bluetooth.println("He's the best person on earth");
else 
Bluetooth.println("Invalid text . Please try again!");
  }
  
int find_distance()
{
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  // Sets the trigPin on HIGH state for 10 micro seconds
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  // Reads the echoPin, returns the sound wave travel time in microseconds
  duration = pulseIn(echoPin, HIGH);
  // Calculating the distance
  distance= duration*0.034/2;
  return distance;
  }

I am wondering if you can help me find what’s wrong with the char to string conversion and comparison . It is not reading the string.
Thank you!

Drop String class, stick to your char buffer and use strcmp() or strcasecmp()

You should start by printing what you got from Bluetooth - if that does not work then don't look further and fix your BT communication first (what hardware do you use, how is it configured and paired? how is that wired?)

The character array obtained is correct (im using the HC-05 module) as i tried printing it out.

void compare(char* A)
{Bluetooth.println();
delayMicroseconds(2);
if (strcasecmp(A,"Distance")==0)
{Bluetooth.print("The distance between the sensor and the object is ");
Bluetooth.println(find_distance());}
else if (strcasecmp(A,"name")==0)
Bluetooth.println("He's the best person on earth");
else 
Bluetooth.println("Invalid text . Please try again!");
  }

I have tried this. It is not giving me the right output for my bluetooth input. Its always going to the else statement.

Don't you have a carriage return integrated in your String ?

Print what you receive between brackets

If you see

[color=red][[/color]Distance[color=red]][/color]

Then you know there is no hidden character but if you see

[color=red][[/color]Distance
[color=red]][/color]

With a carriage return then you know you captured the '\n' in the String you were waiting for or may be a '\r' that was sent before and that's why the string don't match. (You could also display the length of what you got to see if it is 8 )

Side note, you should write your own serial parser and not depend on readBytesUntil(), you can study the Serial Basics post to learn best practices