How to send analog joystick shield Sparkfun value via xbee

I am still a beginner in arduino. I am trying to send the analog values of the x position and y position from the joystick which is connected to xbee coordinator to the xbee router each connected to uno arduino. While the joystick send serial print value, the reciever displays number on serial monitor. My code is to make led on when joystick is not in center position. But it makes the led turn on and of immediately. please reply i really need help

Here is my code

const byte PIN_ANALOG_X = A0;
const byte PIN_ANALOG_Y = A1;

//to calibrate the joystick
const int X_THRESHOLD_LOW = 331;
const int X_THRESHOLD_HIGH = 336;

const int Y_THRESHOLD_LOW = 324;
const int Y_THRESHOLD_HIGH = 330;

int x_position;
int y_position;

int x_direction;
int y_direction;

void setup() {
Serial.begin(9600);
pinMode(PIN_ANALOG_X, INPUT);
pinMode(PIN_ANALOG_Y, INPUT);
}
void loop() {

x_direction = 0;
y_direction = 0;

x_position = analogRead(PIN_ANALOG_X);
y_position = analogRead(PIN_ANALOG_Y);

if (x_position > X_THRESHOLD_HIGH) {
x_direction = 1;
} else if (x_position < X_THRESHOLD_LOW) {
x_direction = -1;
}

if (y_position > Y_THRESHOLD_HIGH) {
y_direction = 1;
} else if (y_position < Y_THRESHOLD_LOW) {
y_direction = -1;
}

if (x_direction == -1) {
if (y_direction == -1) {
Serial.println("q"); // joystick in left down position
} else if (y_direction == 0) {
Serial.println("w"); // joystick in left position
} else {
// y_direction == 1
Serial.println("e"); // left down
}
} else if (x_direction == 0) {
if (y_direction == -1) {
Serial.println("a"); // down
} else if (y_direction == 0) {
Serial.println("s"); // center
} else {
// y_direction == 1
Serial.println("d"); // up
}
} else {
// x_direction == 1
if (y_direction == -1) {
Serial.println("z"); // right down
} else if (y_direction == 0) {
Serial.println("x"); // right
} else {
// y_direction == 1
Serial.println("c"); // right up
}
}}

For receiver :

int ledpin = 13;
char receivedCommand;

/* Declares an array holding various armature positions. If your servo starts grinding when you try 0 or 4, change this array to hold values in the range 1000 - 2000. */

void setup()
{
Serial.begin(9600);
pinMode(ledpin, OUTPUT);
digitalWrite(ledpin, LOW);

}

void loop()
{
if(Serial.available())
{
receivedCommand = Serial.read();
/* If any data is available in the serial interface buffer, it's read into receivedCommand. Reading the buffer automatically empties it of the read character. */

switch(receivedCommand)
{
/* This switch-case construct will evaluate the received character and write the corresponding position to the servo. */

case 's' :
{
/* If the received character is '0', this block will be executed */
digitalWrite(ledpin, LOW);
Serial.println(receivedCommand);

break;
}
case 'a' :
{
/* If the received character is '0', this block will be executed */
digitalWrite(ledpin, HIGH);
Serial.println(receivedCommand);

break;
}
case 'd' :
{
/* If the received character is '0', this block will be executed */
digitalWrite(ledpin, HIGH);
Serial.println(receivedCommand);

break;
}
/* Exits the switch-case block. */
case 'q' :
{
digitalWrite(ledpin, HIGH);
Serial.println(receivedCommand);

break;
}
case 'w' :
{
digitalWrite(ledpin, HIGH);
Serial.println(receivedCommand);

break;
}
case 'e' :
{
digitalWrite(ledpin, HIGH);
Serial.println(receivedCommand);

break;
}

case 'z' :
{
digitalWrite(ledpin, HIGH);
Serial.println(receivedCommand);

break;
}
case 'x' :
{
digitalWrite(ledpin, HIGH);
Serial.println(receivedCommand);

break;
}
case 'c' :
{
digitalWrite(ledpin, HIGH);
Serial.println(receivedCommand);

break;
}
}

}
}

The sender is sending one letter for each of the 9 possible positions. The receiver is supposed to do one of 2 things when it receives input. Actually, 3 - turn the LED on, turn the LED off, or ignore the input. That does NOT require 9 cases.

But it makes the led turn on and of immediately. please reply i really need help

What serial input are you seeing?

When getting two Arduinos to talk to each other, wired or wirelessly, the first thing to do is NOT two write a bunch of code to determine what to send and a bunch of code to deal with what was sent. Just send some KNOWN data, and receive that KNOWN data, and echo it. Then, expand on the receiver side to confirm that KNOWN data is handled correctly. Then make the receiver send variable output. Then, make the receiver handle variable input.

Some pot/servo test code made for sending data to another arduino. The code is designed so as to minimize sending unneeded data packets to prevent choking/overloading the data transmission method.

//zoomkat dual pot/servo test 12-29-12
//view output using the serial monitor

#include <Servo.h> 
Servo myservoS1;
Servo myservoS2;

int potpinS1 = 0;  //analog input pin A0
int potpinS2 = 1;

int newvalS1, oldvalS1;
int newvalS2, oldvalS2;

void setup() 
{
  Serial.begin(9600);  
  myservoS1.attach(2);  
  myservoS2.attach(3);
  Serial.println("testing dual pot servo");  
}

void loop() 
{ 
  newvalS1 = analogRead(potpinS1);           
  newvalS1 = map(newvalS1, 0, 1023, 0, 179); 
  if (newvalS1 < (oldvalS1-2) || newvalS1 > (oldvalS1+2)){  
    myservoS1.write(newvalS1);
    Serial.print("1- ");
    Serial.println(newvalS1);
    oldvalS1=newvalS1;
  }

  newvalS2 = analogRead(potpinS2);
  newvalS2 = map(newvalS2, 0, 1023, 0, 179);
  if (newvalS2 < (oldvalS2-2) || newvalS2 > (oldvalS2+2)){  
    myservoS2.write(newvalS2);
    Serial.print("2- ");    
    Serial.println(newvalS2);
    oldvalS2=newvalS2;
  }
  delay(50); //slow down looping to better read serial monitor 
}

Hi Paul thanks for replying. Yes the sender send one of the 9 cases to other arduino. And the other will recieve the character like s, but the reciever showed integer number while i am sending character

but the reciever showed integer number while i am sending character

It does huh?

What serial input are you seeing?

We still don't know. And, you still aren't sure what you are sending.

i sent you message ok . I send the cases of the joystick left,right,down...etc. i want to read these values and do action

On the serial monitor of the sender i see s and the cases as i moved the joystick. but the reciver show integer and character doesn't belong to what i sent

On the serial monitor of the sender i see s and the cases as i moved the joystick. but the reciver show integer and character doesn't belong to what i sent

It's a good thing at least one of us understands what you are talking about, and can see what you are seeing. Good luck.