arduino read from another serial xbee

i have this code

#include <SoftwareSerial.h>    //  communicate with XBee
SoftwareSerial XBee(2, 3);     //TX = pin 2
                               //RX = pin 3
int inputPin = 4; // PIR sensor
int ledPin   = 13; 
int pirState = LOW; // assuming no motion detected
int val = 0; // variable for reading the pin status

void setup() 
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(inputPin, INPUT); // declare sensor as input

void loop(){
val = digitalRead(inputPin); // read input value
if (val == HIGH) { // check if the input is HIGH
digitalWrite(ledPin, HIGH); // turn LED ON
if (pirState == LOW) { //turn on PIR
Serial.println("E"); // print on the output change, not state

pirState = HIGH;
} else {
digitalWrite(ledPin, LOW); // turn LED OFF
if (pirState == HIGH){ // we have just turned of

pirState = LOW;

that i want to communicate with another serial through the xbee

i have looked at this code

#include <SoftwareSerial.h>

SoftwareSerial xbee(2, 3); // RX, TX

void setup()

    Serial.println( "Arduino started receiving bytes via XBee" );

    // Set the data rate for the SoftwareSerial port.

void loop()  {
    int temp =;

    Serial.print("Character received:");

but it’s a temperature code and it sends only “1s” and when motion is detected from my first arduino “255”

how can i code it so that it only sends what the first arduino is sending which is the ‘‘e’’?

how can i code it so that it only sends what the first arduino is sending which is the ''e''?

You need to read data from the SoftwareSerial instance (that the XBee is connected to) and send that data using Serial.print().

The read() method returns an int, so that it can tell you you screwed up calling it when there is nothing to read.

If you only call read() after determining (using available()) there there is data to read, then the data will be in the low order byte of the int. That means that you could use a byte sized variable to hold the data, such as a char. THAT will make a big difference in how the program behaves.


You may find some useful ideas in serial input basics