wireless communication between arduinos using xbees; stuck in code

I want the user to type a text on the serial monitor of arduino mega 2560 and want that text to be transmitted using the xbees (both series 1) to the arduino uno and displayed on its serial monitor. i am unable to do so.

For example, heres a code that i found in a tutorial:

FOR SENDER (TRANSMITTER XBEE ATTACHED TO ARDUINO MEGA 2560):

void setup() {
Serial.begin(9600);
}
void loop() {
Serial.println("H"); //turn on the LED
delay(1000);
Serial.println("L");//turn off the LED
delay(1000);
}

this code will be uploaded on arduino mega (sender).

FOR RECEIVER (RECEIVER XBEE ATTACHED TO ARDUINO UNO)

char msg = ' ';   //contains the message from arduino sender
const int led = 13;   //led at pin 13
void setup() {
Serial.begin(9600);
pinMode(led,OUTPUT);
}
void loop() {
while(Serial.available() > 0) {
           msg=Serial.read();
           if(msg=='H') {
               digitalWrite(led,HIGH);
           }
           if(msg=='L') {
                digitalWrite(led,LOW);
           }
delay(1000);
}
}

this code will be uploaded on arduino uno (receiver).

this code when uploaded on both the arduinos will first transmit H that will blink the led on the arduino uno and then will transmit L that will turn off the led. But i want the user to enter the letter H or L at run time that would further control the led. i am unable to do so.

Thanks. Any kind of help will be much appreciated :slight_smile:

But i want the user to enter the letter H or L at run time that would further control the led. i am unable to do so.

Enter it where? You have the Serial port talking to the XBee. You can't use that to talk to the PC, too.

What kind of XBee shield are you using?