Send a float value from one Xbee to another

So I have two XBee®-PRO 900HP/XSC RF Modules connected to two different arduinos and I am trying to send a value from a temperature sensor which is connected to one of the arduinos to the other.The problem is that the value that is received is not a decimal number but rather an integer
even though it is sent as a float.Here's what my serial monitor shows;
coordinator or sender;
COORDINATOR SERIAL MONITOR

and here is what the receiver receives;
RECIEVER

Is it a problem with the code you didn't post?

coordinator's code

It seems human communication has regressed - resorting to posting pictures, instead of text.

I despair.

and the receiver's

Should I post a picture of a book?

1 Like

Instead of trying to be funny can you at least give me an idea of what to do?

Funny?
You think it's funny?

Post code, not pictures - I can't compile code in Photoshop.

Why is this so hard to comprehend?

ok coordinator's code

#include<SoftwareSerial.h>
#include <XBee.h>
XBee xbee = XBee();
SoftwareSerial XBee(2,3);
const int SENSOR_PIN = 5; // Arduino pin connected to DS18B20 sensor's DQ pin

OneWire oneWire(SENSOR_PIN);         // setup a oneWire instance
DallasTemperature tempSensor(&oneWire); // pass oneWire to DallasTemperature library

float tempCelsius;    // temperature in Celsius
float tempFahrenheit; // temperature in Fahrenheit

void setup()
{
  Serial.begin(9600); // initialize serial
XBee.begin(9600);
  tempSensor.begin();    // initialize the sensor
}


void loop()
{
float temp;
  tempSensor.requestTemperatures();             // send the command to get temperatures
  tempCelsius = tempSensor.getTempCByIndex(0);  // read temperature in Celsius
 
temp= tempCelsius ;

XBee.write(temp);
  Serial.print("Temperature: ");
  Serial.print(temp);    // print the temperature in Celsius
  Serial.println("°C");
 

  delay(500);
}

and what the serial monitor displays;

Temperature: 23.31°C
Temperature: 23.31°C
Temperature: 23.31°C
Temperature: 23.31°C
Temperature: 23.31°C
Temperature: 23.31°C
Temperature: 23.31°C
Temperature: 23.31°C
Temperature: 23.31°C
Temperature: 23.31°C
Temperature: 23.31°C
Temperature: 23.31°C
.....

Receiver's code

#include<SoftwareSerial.h>
#include <XBee.h>
XBee xbee = XBee();

SoftwareSerial XBee(3,2);
float data;

void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
XBee.begin(9600);

}

void loop() {
  // put your main code here, to run repeatedly:


  if (XBee.available())
  { // If data comes in from XBee, send it out to serial monitor
    //XBee.flush();
    data = XBee.read();
    Serial.println(data);
    }
  }

and serial monitor

23.00
23.00
23.00
23.00
23.00
23.00
23.00
23.00
.......

Is that a bit better?

Write transmits a byte. The compiler converted your float for you which left you with 23.

The receiver got 23 in a single byte and converted it to a float, hence 23.00 when printed.

Much better.

I'm going to guess it is because the XBee read function returns an integer type.

Which XBee library did you install?

is there any way to use a command that can transmit a float value?

Yes, send the four bytes that make up the float, and reassemble them at the receiver.

Which XBee library are you using?

A library by FFTechBrasil

Link?

Instead of this

XBee.write(temp);

Try this:

XBee.print(temp);

Then, you will need to read the data in correctly on the other end. To prepare for that adventure, it would be a good idea to study the Serial Input Basics tutorial on the forum.

I have already tried it but the serial monitor displays completely different numbers.That's what I mean

50.00
55.00
46.00
48.00
48.00
45.00
49.00
50.00
55.00
46.00
48.00
48.00

Tried what? Post the code, using code tags.

I have already tried

XBee.print(temp);

instead of
XBee.write(temp);

#include<SoftwareSerial.h>
#include <XBee.h>
XBee xbee = XBee();

SoftwareSerial XBee(3,2);
float data;

void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
XBee.begin(9600);

}

void loop() {
  // put your main code here, to run repeatedly:


  if (XBee.available())
  { // If data comes in from XBee, send it out to serial monitor
    //XBee.flush();
    data = XBee.print(); /*This line of code that you suggested 
to change but as i said the serial monitor displays those
 complete different numbers I sent earlier*/
    Serial.println(data);
    
  }
}