connection between two ARDUINO with xbee

I have a setup where two xbee modules are talking to each other, both using xbee shields, one attached to an uno arduino and the other a mega arduino. One xbee sends the data and the other receives it and switch on or off a LED.
the problem is the receiver one don’t work
this is the sender code

int led = 13;
const int bouton = 2; String inputString;
void setup() {
pinMode(led, OUTPUT);
Serial1.begin(9600);
Serial.begin(9600);
digitalWrite(led, LOW);


}
void loop() {
while (Serial.available() ) {
    // get the new byte:
    delay(3);  
    char inChar = Serial.read();
    // add it to the inputString:
    inputString += inChar;
    }
  if (inputString.length() >0) {
   Serial.println(inputString);
   Serial1.println(inputString);
   inputString=""; 
   }
 }

thi is the receiver one

const int led = 13; //led at pin 13
String inputString;
void setup() {
Serial.begin(9600);//Remember that the baud must be the same on both arduinos
pinMode(led,OUTPUT);
}
void loop() {

while (Serial.available() ) {
    // get the new byte:
    delay(3);  
    char inChar = Serial.read();
    // add it to the inputString:
    inputString += inChar;
    }
  if (inputString.length() >0) {
    Serial.println(inputString);
   if (inputString = "on"){    
   digitalWrite(led,HIGH);
  }

if (inputString = "off"){
 digitalWrite(led,LOW);
 Serial.println(inputString);
}
  inputString="";
 } 
 
}

what i get from the receiver when i send anything is
on
off

if(input string="on")

Your two conditional tests on inputString need ==

it still doesn't work :confused:
i receive the sting on or off but the LED still doesn't switch on or off

it still doesn’t work :confused:
i receive the sting on or off but the LED still doesn’t switch on or off

As far as I can tell, you haven’t fixed your code.
As far as I can tell, your LED is not wired correctly.

this is the new receiver code

int led = 13;
String inputString;
void setup() {
  // put your setup code here, to run once:
pinMode(led, OUTPUT);
Serial.begin(9600);

}
void loop() {
  while (Serial.available() ) {
    // get the new byte:
    delay(3);  
    char inChar = Serial.read();
    // add it to the inputString:
    inputString += inChar;   
}

if (inputString.length() >0) {
    Serial.println(inputString);
if (inputString == "on"){
    digitalWrite(led,HIGH);
     Serial.println("LED ON");
    }

if (inputString == "off"){
  digitalWrite(led,LOW);
  Serial.println("LED OFF");
}
inputString=""; 
}
}

What does your Serial output look like?

I get on the serial monitor of ARDUINO UNO what i wrote in the serial monitor of ARDUINO MEGA but the LED don't switch on or off :confused:

Your sending code likely has Newline or Carriage Return or both at the end of “on” and “off” entered in the serial monitor.

You can enter the “on” “off” with the monitor set to no line ending, or else build the the line ending into the comparison. For example

if (inputString == "on\n" and if (inputString == "off\n"))

for a newline termination.

this is going to be more strange !! the LED still always don't switch on

actually this is make it works

if (inputString == "on\r\n" and if (inputString == "off\r\n"))