Go Down

Topic: Please check my code? XBee (Read 33 times) previous topic - next topic

llnunu

Hi there,
I would appreciate if somebody could look over my code and see if there are any errors.
This is the initial code that I have for my PIR connected to an XBee.
Whenever I see it on the XCTU I see ''?'' instead of ''E''.

Code: [Select]

#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;
}
}
}



Thanks so much

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy