# Xbee - Transmit string data and convert it to a floating point number.

**URL:** <https://forums.digi.com/t/xbee-transmit-string-data-and-convert-it-to-a-floating-point-number/14934>\
**Category:** XBee & XBee Gateway\
**Tags:** arduino, floating-point, xbee\
**Created:** [June 4, 2015, 9:02am UTC](https://forums.digi.com/t/xbee-transmit-string-data-and-convert-it-to-a-floating-point-number/14934 "2015-06-04T09:02:28Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![dspfun](https://avatars.discourse-cdn.com/v4/letter/d/6de8d8/32.png) [@dspfun](https://forums.digi.com/u/dspfun)\
**Post date:** [June 4, 2015, 9:02am UTC](https://forums.digi.com/t/xbee-transmit-string-data-and-convert-it-to-a-floating-point-number/14934/1 "2015-06-04T09:02:28Z")

</div>

I would like to transmit a string from one Arduino/Xbee to another and convert the string to a floating point number at the second Arduino for processing using AT. The Arduino will send the information as a string and display it to the monitor. If I try to convert the string to a floating point number on the receiving Arduino the atof command does not work. I have tried various different formats for the string data but the output is the same.

I’ve attached a link to the serial monitor output. [https://plus.google.com/u/0/photos/100758297290516264231/albums/6156285809144715009](https://plus.google.com/u/0/photos/100758297290516264231/albums/6156285809144715009)

Here is the sending code;

#include  
#include

float DO\_float= 9.62;

SoftwareSerial XBee(2, 3); // RX, TX

void setup()  
{  
Serial.begin(9600); //enable the hardware serial port  
XBee.begin(9600);  
}

void loop(){

XBee.println(DO\_float);  
Serial.print(“DO:”); //print out “DO:”  
Serial.print(" ");  
Serial.println(DO\_float,4);

delay(500); // delay half a second between transmission

}

Receiving code;

#include  
#include

SoftwareSerial XBee(2, 3); // RX, TX

float DO\_float=0; //used to hold a floating point number that is the D.O.

void setup()  
{  
XBee.begin(9600);  
Serial.begin(9600);  
}

void loop()  
{

if (XBee.available()) { // If data comes in from XBee, send it out to serial monitor

```
  char DO, buf[100];
  DO = XBee.read();
  DO_float = atof((char *)buf);
  Serial.print(DO);
  //Serial.println(DO_float); //uncomment to print floating point result

}

```

}
