Need Help trouble shooting value in Anemometer readin/ xbee data transfer

Hi All,

I am so close to getting what I need but I am getting some noise in my data. I have an Anemometer hooked up to my arduino and I am sending the data through an transmitter xbee chip hooked up to arduino 1 to a reciever xbee that is hooked up to arduino 2. For the most part, my data comes in and can be read on the serial monitor of arduino 2 but I have intermitten spiked values around 13,400 or even 10,652. These values spike two or three times in a row, then gives me my actual value, drops to 0, then spikes again and give me the actual value. All this happens when I spin the anemometer. Here is my code:

Transmitter Xbee (Arduino 1)

/***********************************************************************************************************/
/*                                               TXB CODE BELOW                                            */
/***********************************************************************************************************/
// Defines/Macros
#define BAUD_RATE 9600

#define MIN_ANGLE 0
#define MID_ANGLE 90
#define MAX_ANGLE 180

#define BITS_PER_BYTE 8
#define TX_BUF_SIZE   5
#define CHAR_MASK     0xFF

#define FP_PRECISION 4



// Defines the Arduino pins that the anemometers are connected to
const int pinR = A0,
          pinL = A1,

// Delay between sensor readings, measured in milliseconds (ms)
          sDelay = 500;

/**********************************
 * Anemometer Technical Variables *
 ********************************************************
 * The following variables correspond to the anemometer *
 * sold by Adafruit, but could be modified to fit other *
 * anemometers.                                         *
 ********************************************************/
const float VOLTAGE_CONVERSION_CONST = 0.004882814, // Proportionality constant
                                                    // between voltage and
                                                    // min (0) and max (1023)
                                                    // values of analogRead().
            MPS_TO_MPH_CONVERSION_CONST = 2.23694,  // Proportionality constant
                                                    // (approximate) between m/s
                                                    // to mph.
            MIN_VOLTAGE_L = 0.48, // Left Anemometer mininum output voltage in mV. (Found empirically)
            MIN_VOLTAGE_R = 0.48, // Right Anemometer minimum output voltage in mV. (Found empirically)
            MAX_VOLTAGE = 2.0,    // Anemometer maximum output voltage in mV.
            MAX_WSPEED = 32.0;    // Wind speed in meters/sec corresponding to
                                  // maximum voltage

union {byte b[sizeof(float)]; float f = 0.0;} buf;

float temp = 0.0;



/**************************************** MAIN PROGRAM ****************************************/
void setup (void) {Serial.begin(BAUD_RATE);}    // Start the serial connection to XBee

float getVoltage (const int pin) {return analogRead(pin) * VOLTAGE_CONVERSION_CONST;}

/**********************************************
 * Returns the wind speed (mph) corresponding *
 * to a read-in voltage at an analog pin.     *
 **********************************************/
float getWindSpeed (float voltage, const int pin) {
    /************************************************
     * If wind speed <= minimum voltage,             *
     *   set wind speed to 0.                       *
     * Otherwise, the wind speed is linear with the *
     *   read-in voltage.                           *
     ************************************************/
    float r;
    switch (pin) {
        case pinR:
            r = (voltage <= MIN_VOLTAGE_R) ? 0.0 :
                ((voltage - MIN_VOLTAGE_R)*MAX_WSPEED*MPS_TO_MPH_CONVERSION_CONST)/(MAX_VOLTAGE - MIN_VOLTAGE_R);
        case pinL:
            r = (voltage <= MIN_VOLTAGE_L) ? 0.0 :
                ((voltage - MIN_VOLTAGE_L)*MAX_WSPEED*MPS_TO_MPH_CONVERSION_CONST)/(MAX_VOLTAGE - MIN_VOLTAGE_L);
    }
    return r;
}

void transmit (void) {
    Serial.write(SOP);
    for (int i = 0; i < sizeof(buf.f); i++) {Serial.write(buf.b[i]);}
    Serial.write(EOP);
}

void loop (void) {
    /************************************************
     * Get values between 0 and 1023 from the
     * analog pin connected to the right and left   *
     * anemometers.                                 *
     ************************************************
     * Convert voltage value to wind speed using    *
     * range of max and min voltages and wind speed *
     * for the anemometer on the right.             *
     ************************************************/
    /*
    float rv = getVoltage(pinR), lv = getVoltage(pinL);
    Serial.print("right voltage = ");
    Serial.println(rv);
    Serial.print("right windspeed = ");
    Serial.println(getWindSpeed(rv, pinR));
    Serial.print('\n');
    
    Serial.print("left voltage = ");
    Serial.println(lv);
    Serial.print("left windspeed = ");
    Serial.println(getWindSpeed(lv, pinL));
    Serial.print('\n');
    */
    //buf.f = getWindSpeed(getVoltage(pinR), pinR) - getWindSpeed(getVoltage(pinL), pinL);
    buf.f = getWindSpeed(getVoltage(pinR), pinR);
    transmit();
}

Reciever Xbee (Arduino 2)

/***********************************************************************************************************/
/*                                               RXB CODE BELOW                                            */
/***********************************************************************************************************/
const int BAUD_RATE  = 9600,
          NUM_SERVOS = 1,
          MIN_ANGLE = 0,
          MID_ANGLE = 90,
          MAX_ANGLE = 180,
          pins[] = {9};  // Number of elements should equal NUM_SERVOS

const float MPS_TO_MPH_CONVERSION_CONST = 2.23694,
            MIN_WS = 0.0,
            MAX_WS = 32.0 * MPS_TO_MPH_CONVERSION_CONST;

Servo servos[NUM_SERVOS];

int positions[NUM_SERVOS];
union {byte b[sizeof(float)]; float f;} buf;

void setup (void) {
    // Set Baud rate
    Serial.begin(BAUD_RATE);
    
    // Attach to corresponding pin in pins array
    for (int i = 0; i < NUM_SERVOS; i++) {
        servos[i].attach(pins[i]);
        positions[i] = MID_ANGLE;
    }
}


float getRx (void) {
    int i = sizeof(float);
    
    do {
      if (Serial.available() > 0) {
        buf.b[i--] = Serial.read();
      }
    } while (i > 0);
}

void updateServoPosition (float value, int pos_index) {
    Serial.print("value = ");
    Serial.println(value);
    
    int angle = map(value, MIN_WS, MAX_WS, MAX_ANGLE, MIN_ANGLE),
        delta = (positions[pos_index] < angle) ? 1 : -1;
    
    while (positions[pos_index] != angle) {
        positions[pos_index] += delta;
        servos[pos_index].write(positions[pos_index]);
    }
    Serial.print("position[");
    Serial.print(pos_index);
    Serial.print("] = ");
    Serial.println(positions[pos_index]);
    Serial.print('\n');
    Serial.flush();
}

void loop (void) {
    getRx();
    updateServoPosition(buf.f, 0);
    //delay(INTERMISSION);
}

What range of values are you sending? Does sending the data in binary mode really save you any bytes?

          pins[] = {9};  // Number of elements should equal NUM_SERVOS

Why do you need a one element array?

    do {
      if (Serial.available() > 0) {
        buf.b[i--] = Serial.read();
      }
    } while (i > 0);

You send 6 bytes and then read 4, and assume that the 4 bytes are the ones that make up a float. No wonder you get crap.

Even if you got good data, you pass the float to map(), which expects an integer. Doesn't make sense to me.