Control LED Brightness using 2-Axis joystick over Xbee's problem :(

So i'm pretty new to Arduino but coming along fast.
What i'm trying to do is use one direction of a 2-axis joystick to control the brightness of an LED across the room. The problem is the value i'm reading seems like garbage. I get 2,3,13,14 over and over when they start to talk. Even powering off the joystick the numbers continue for a bit.

I have 2 Xbee Series 2 running in mess mode. They talk to eachother and can read serial sent from one to the other. Once i plug the Xbee into the 2nd Arduino the garbage starts.

Here are the 2 projects being used.

int UD = 0;
int LR = 0;

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

void loop() {
  UD = analogRead(0);
  LR = analogRead(1);
 // Serial.print("UD = ");
 // Serial.print(UD, DEC);
 // Serial.print(", LR = ");
 // Serial.println(LR, DEC);
Serial.println(UD);
  delay(200);
}
#include <LiquidCrystal.h>
int LED = 9;
LiquidCrystal lcd(12,11,5,4,3,2);

void setup()
{
  lcd.begin(16,2);
  Serial.begin(9600);
  pinMode(LED, OUTPUT);
}
void loop()
{
  lcd.clear();
  while(Serial.available() == 0);
  int data = Serial.read();
  int val = map(data,0,1023,0,255);
  analogWrite(LED,val);
  lcd.setCursor(0,1);
  lcd.print(val);
  Serial.flush();
  delay(1000);
}

I get 2,3,13,14 over and over when they start to talk.

Do you have the same problem wired?

I have 2 Xbee Series 2 running in mess mode.

The XBees only operate in two modes - AT or API. If you are trying to use a new mode, your on your own.

It never ceases to amaze me when people buy the more expensive/complicated mesh network models to do point to point stuff. If you want to do point to point stuff, why didn't you but point to point models?

On the sender, you are sending a value AS A STRING followed by a carriage return and a line feed. On the receiver, you are expecting to get a number that corresponds to the pot reading.

Not going to happen.

  Serial.flush();

You'll want to get rid of this. Trust me.

Since you are mapping the int to a byte on the receiver, make life easier for yourself. Do that mapping on the sender, then use Serial.write() to send the byte (not an int) as binary data.

Thank you that makes a lot of sense.

The reason for the Zbee's that have mess capabilities is that my over all plan is to have multiple robots over a larger area. Just trying baby steps without buying multiple parts. I'm on a budget so my parts need multiple uses.