I'm transmitting: Temperature: 28.22C

and on the receiving end I'm receiving the whole tranmission as a string. I'm trying to spilt Temperature to leave it as a string and 28.22 as a float to compare, how do I do that ?

TX end hardware: (Arduino Uno board with Xbee S1) to computer RX end hardware: (Arduino Uno board with Xbee S2) to computer

  • 1
    Is the "receiving end" an Arduino or a computer? If it's a computer, you should tell which language you use and probably ask your question on stackoverflow.
    – jfpoilpret
    Jun 10 '15 at 4:28
  • Hi, the receiving end is an Arduino Uno board which is hooked up to the computer. The transmitting end is also hooked up to an Arduino Uno board. Both communication goes through Xbee S1 card
    – user10566
    Jun 10 '15 at 8:02

Okk very simple approach :-

Suppose this is your string variable inStr = "Temperature: 28.22C"

String inStr = "Temperature: 28.22C";
int indexOfSpace = inStr.indexOf(' ');
//this stores the address of the space character in the string.
int indexOfC = inStr.indexOf('C');

String Temp = inStr.substring(indexOfScace+1,indexOfC);
//as the parameter for the function is supposed to be the starting point of the string to
 be extracted and one more than its ending point.

//Now to convert to float

float TempFlo = Temp.toFloat();
  • @user10566 if this answer worked please consider marking it as accepted so that the SE system does not bump it up as an unanswered question.
    – RSM
    Jun 4 '16 at 19:47

I suppose your communication is working... In order to retrieve a floating number from a string you might use toFloat() function. You can watch the reference page here to understand how does it work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.