Hi experts!
Im a newbie in using arduino and Im currently working on a simple project. I would like to automate my room lights using motion sensor, wirelessly. I need help on making LED turn ON and OFF using PIR motion sensor wirelessly, that is, i will be using two arduino uno and two xbee pro for the transmitter and receiver side. Im having problems on making my project work. It seemed that the receiver side is not receiveing the same data that i transmitted on the transmitter side. I hope you guys can help me. Here are my codes:
For the TX side:
int motionPin =0;
void setup()
{
Serial.begin(9600);
pinMode(motionPin, INPUT);
}
void loop()
{
int val = analogRead(motionPin);
Serial.println(val);
delay(50);
}
For the RX side:
int ledPin = 10;
int lastDist = 0;
int currentDist = 0;
int thresh = 200;
void setup()
{
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
}
void loop()
{
while(Serial.available() == 0);
int currentDist = Serial.read();
Serial.println(currentDist);
if (currentDist < lastDist + thresh || currentDist > lastDist - thresh)
{
digitalWrite(ledPin, HIGH);
delay(1500);
}
else
{
digitalWrite(ledPin, LOW);
}
lastDist = currentDist;
}
