How to detect a character in a message received through XBee

Hello everyone! I am doing a project in Home automation through ZigBee. I am working on a prototype which consists of two modules. One is sensing module and other is the co-ordinator module. The sensing module senses the motion through a PIR and transmits 1 if the value through PIR is HIGH or 0 is value through PIR is LOW. The co-ordinator module is successfully receiving the values and messages as intended. But when I need to print a message when the received value is 1 or 0, it isn’t working. Please check the code for co-ordinator(Receiver) and mention the corrections needed to be done.

#include <SoftwareSerial.h>


SoftwareSerial example(10,11);
void setup() {
  Serial.begin(9600);
  example.begin(9600);
  //example.println("Reciever is running");
}

void loop() {
  // put your main code here, to run repeatedly:
  if(example.available()){
    Serial.write(example.read());
    char rx = example.read();
    if((rx-'0')==1){
      Serial.println("Motion Detected");
    }  
  }
  /*if(Serial.available()){
    example.write(Serial.read());
  }*/
}

The SoftwareSerial is needed as the Xbee also needs serial transmission. I just want to know how to modify the above code so that “Motion Detected” is prined on serial monitor when the value received is 1.

What do you see if you print rx ?

See comments there is a hint in there:

if(example.available()){ // if I have one character at least available from the xbeed
   Serial.write(example.read()); // read it, removing it from the incoming buffer, and print it
   char rx = example.read(); // hum... what would I be trying to read here??? Who knows....
   ....

The sensing module senses the motion through a PIR and transmits 1 if the value through PIR is HIGH or 0 is value through PIR is LOW

Are you sending ‘1’ and ‘0’ or the numerical 1 and 0??


side note
(You should also set your Serial.begin at 115200 as well as your IDE seeial monitor to ensure your debug trace do not slow down too much your code which could cause timing issues)

To make it a little clearer, why read twice? The character is gone after the first read.