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
XBee.begin(9600);
Serial.begin(9600);
}
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
XBee.write(Serial.read());
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.begin(9600);
Serial.println( "Arduino started receiving bytes via XBee" );
// Set the data rate for the SoftwareSerial port.
xbee.begin(9600);
}
void loop() {
int temp = xbee.read();
Serial.print("Character received:");
Serial.println(temp);
delay(1000);
}
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’’?