Serial.read() - XBee - Not firing Else If

I am very new to Arduino (about a week) and have been searching for a resolution to my simple issue.

I currently am trying to do some communication test between a PC and Arduino Uno using an XBee in AT mode.

My test is to send characters from the computer to the XBee and process through conditional statements.

I don't believe this issue is with configuration of the XBees, for I am able to communicate successfully when I watch the Serial monitors.

Here is the code I am running on the Arduino:

#include <SoftwareSerial.h>

SoftwareSerial xBee = SoftwareSerial(1, 0);

int Led = 9;

void setup()  
{
  pinMode(Led, OUTPUT);
  xBee.begin(9600);  
}

void loop()
{  
  if(xBee.available()> 0) 
  {
    if (xBee.read() == 'r')
    {
       digitalWrite(Led, HIGH);
       xBee.write("Led On");
       delay(10);       
    }
    else if (xBee.read() == 'o')
    {
      digitalWrite(Led, LOW);   
      xBee.write("Led Off");
      delay(10);      
    }
    else
    {
      xBee.write("NR"); // Testing for not recognized characters
    }
    delay(10);
  }
  delay(10);
  
}

I can turn the LED when sending the character 'r' from the PC to the XBee. The intended result is received back as well. When I try to send the character 'o' from the PC the LED stays on and I get the response of "NR".

This same result happens with different characters in the else if statement, sending character 'o' as the first character, changing to just if statements, and changing the initial condition to - while xBee.available().

Any help or guidance in the right direction would be appreciated.

I think your statements are not nested correctly.
Use extra braces { } round them to make sure you identify what if each else belongs to.
However you would be better off using a switch / case statement. Note that there may be junk on the back end of a recieved message like carriage returns that could trigger the "NR" responce more often that you would want.

The issue was corrected by changing the code to:

#include <SoftwareSerial.h>

SoftwareSerial xBee = SoftwareSerial(1, 0);

int Led = 9;

void setup()  
{
  pinMode(Led, OUTPUT);
  xBee.begin(9600);  
}

void loop()
{   
  if(xBee.available()> 0) 
  {
    char read_value = xBee.read();    
    if ( read_value == 'r')
    {
       digitalWrite(Led, HIGH);
       xBee.write("Led On");
       delay(10);       
    }
    else if ( read_value == 'o')
    {
      digitalWrite(Led, LOW);   
      xBee.write("Led Off");
      delay(10);      
    }
    else
    {
      xBee.write("NR"); // Testing for not recognized characters
    }
    delay(10);
  }
  delay(10);

}