Help with Temperature Sensor

I am using 2 XBee 802.15.4 (Series 1).
My goal is to have XBee A gather and send the temperature data over to XBee B. Then, XBee B will display the temperature on the serial monitor screen on the Arduino IDE.

Currently, the serial monitor screen displays something like this:
Goodnight moon!
23.24
23.24
23.24
23.24
23.24
23.24
23.24
23.24
23.24
23.24
23.222222222222232222222222224.22222222222
.2222222222222
.2222222222222
.3222222222222223322222222222233222222222

The problems occurs in the last 4 lines of the display.

The code for XBee A is:

#include <NewSoftSerial.h>

NewSoftSerial mySerial = NewSoftSerial(2, 3);

void setup() {
pinMode(13, OUTPUT);
Serial.begin(9600);
mySerial.begin(9600);
}

int temperaturePin = 0;

void loop() // run over and over again
{
float temperature = getVoltage(temperaturePin); //getting the voltage reading from the temperature sensor
temperature = (temperature - .5) * 100; //converting from 10 mv per degree wit 500 mV offset
//to degrees ((volatge - 500mV) times 100)
mySerial.println(temperature); //printing the result
delay(100); //waiting a second
}

/*

  • getVoltage() - returns the voltage on the analog input defined by
  • pin
    */
    float getVoltage(int pin){
    return (analogRead(pin) * .004882814); //converting from a 0 to 1024 digital range
    // to 0 to 5 volts (each 1 reading equals ~ 5 millivolts
    }

The code for XBee B is:

#include <NewSoftSerial.h>

NewSoftSerial mySerial = NewSoftSerial(3, 2);

void setup() {
pinMode(13, OUTPUT);
Serial.begin(9600);
Serial.println(“Goodnight moon!”);
// set the data rate for the SoftwareSerial port
mySerial.begin(9600);
}

void loop() // run over and over again
{

if (mySerial.available()) {
Serial.print((char)mySerial.read());
}
if (Serial.available()) {
mySerial.print((char)Serial.read());
}
delay(100);
}

I’m not sure what the problem is. I guess the problem involve serial buffer overflow. Is there a way to overcome this serial buffer overflow? Could the serial buffer overflow be the problem?

Any help or suggestion would be appreciated.

I would do three things. On the sender, keep track of the last temperature sent. Then, only send a new temperature when there has been a change.

On the receiver, you are echoing everything that you read from the XBee to the serial port as well as broadcasting everything to the other XBee. There is no reason for this.

Connect both Arduinos to separate serial ports, and run two versions of the IDE with different ports selected. Then, run two versions of the Serial Monitor - one for each Arduino.

Finally, stuff is being written to the Serial Monitor, but you have no idea what it is. Preface everything that is written to the serial monitor with some meaningful description:

if(mySerial.available() > 0)
{
   char aChar = mySerial.read();
   Serial.print("Received from sender: ");
   Serial.println(aChar);
}

This will result in a lot more lines being written to the serial monitor, but it will become very clear where the problem is occurring.